User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 392,021 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,262 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:

HELP me as soon as possible ..!

Join Date: Sep 2004
Posts: 6,021
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 414
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: HELP me as soon as possible ..!

  #4  
May 6th, 2005
>it always takes the last name entered
That's because you're using a pointer. When you assign name to s[i], s[i] points to name. When the loop is done, all of the pointers still point to name, which contains the last name entered. To fix this, use arrays instead:
char s[10][100];
char name[100];

...

cin.width(99); // Protection from buffer overflow
cin>> name;
strcpy(s[i], name);
>when I enter a name to search for ,I face a debug
You mean you get an access violation when you try to write to an uninitialized pointer. You seem to have trouble with pointers, so I would suggest using arrays instead for any project. Leave the pointers for toy programs meant to experiment with features:
char j[100];

...

cout << "Input the employee name:" << endl;
cin.width(100);
cin >> j ;
Member of: Beautiful Code Club.
Reply With Quote  
All times are GMT -4. The time now is 10:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC