CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    20

    Unhappy Runtime Error - Dynamic Arrays

    i m getting a runtime error and the program skips the first attribut i.e name,and gives a runtime error at the second one.compiler gives some warning about gets".\Assignment 3_Question 4.cpp(118) : warning C4996: 'gets': This function or variable may be unsafe. Consider using gets_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    "

    my code is :
    Code:
    char *addcustomer(char **p,int n)
    {
    	
    
    	cout << " ------- Add Customer Record --------" << endl << endl;
    
    	
    
    	
    	
     for(int i=0;i<n;i++)
     {
    	cout << "Please Enter Customer Name: " ;
    	
    	cin.getline(p[i],20,'\n');
    	
    	cout << endl;
    	
    	cout << "Please Enter Customer NIC Number: " << endl;
    
    	gets(p[i+1]);
    	
    	//cout << p[i+1]<< endl;
    
    	cout << "Please Enter Customer Telephone: Number " << endl;
    	
    	gets(p[i+2]);
    	
    	//cout << p[i+2]<< endl;
    
    	cout << "Please Enter Customer Room Number: " << endl;
    	
    	gets(p[i+3]);
    	
    	//cout << p[i+3]<< endl;
    
    	cout << "Please Enter Customer Entry Date and Time: " << endl;
    
    	gets(p[i+4]);
    	
    	//cout << p[i+4]<< endl;
    
    	cout << "Please Enter Customer Exit Date and Time: " << endl;
    	
    	gets(p[i+5]);
    	
    	//cout << p[i+5]<< endl;
    
    	cout << "Please Enter Customer Payments: " << endl;
    
    	gets(p[i+6]);
    	
    	//cout << p[i+6]<< endl;
    
    	cout << "Please Enter Customer Status: " << endl;
    
    	gets(p[i+7]);
    	
    	//cout << p[i+7]<< endl;
    	
     }
    
    
    
    return 0;
    
    }
    
    int _tmain()
    
    {
    	int choice,n;
    
    	cout << "Please Enter the number of records you want to Enter: " << endl;
    
    	cin>>n;
    
    	char **p=new char*[n];
    	cin.ignore();
    	
    	for(int i=0;i<n;i++)
    	{
    		p[i]=new char[20];
    	}
    
    	 cin.ignore();
    .
    .
    .
    .
    addcustomer(p,n);
    
    .
    .
    .
    return 0;
    }

    thanks in advance!

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: Runtime Error - Dynamic Arrays

    I'm not sure exactly what you are trying to do ... but in addcustomer,
    look at the for loop, when "i = n-1"

    1) you do a getline() using p[i] ... ok

    2) you do a gets() in p[i+1] , p[i+2] , ... , p[i+7] ... these are
    past the bounds of the array.

    3) Why are you mixing getline() and gets() ?

  3. #3
    Join Date
    Mar 2009
    Posts
    20

    Re: Runtime Error - Dynamic Arrays

    i just used both of them to run my code,but none of them works,both give error,i just wanted to show that i have tried both of them!

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Runtime Error - Dynamic Arrays

    Let's say that you're on the iteration of the loop when i == n-1. At that point, where are you trying to store the telephone number?

  5. #5
    Join Date
    Aug 2008
    Location
    India
    Posts
    186

    Red face Re: Runtime Error - Dynamic Arrays

    i am a bit confused in your for loop..... what will happen when the loops runs after entering 1st record.... i think it will overlap your previous data(record).....
    though m not sure whether i am correct or not....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured