| | |
Searching array problems
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2007
Posts: 21
Reputation:
Solved Threads: 0
Hey, i am trying to search an array of surnames. I am entering in a surname, and if that surname is in the array, i want to to bring out all other details for that surname that are stored in a structure. At the moment, i have this working for the reference number. The code for that is:
This then, if found, out puts all the details in the Quote structure for all the details of that record number.
However, when i try this for the surname, which is very similar, it doesn't work:
SearchName takes in the surname i enter along with some other stuff after it. I was wondering how to get rid of all the stuff after the surname to get this to work. I think its something to do with '/0' but that just stores up the remaining space with /0. It wont bring out the results for Snape as searchname is stored as Snape/0/0/0/0.
Any help would be great.
Ian
cout << "Please enter an associate reference number :" << endl;
cin >> SearchNum;
while((RecNum < MAX_QUOTES) && (SearchNum != Quote[RecNum].RefNumber))
{
RecNum++;
}This then, if found, out puts all the details in the Quote structure for all the details of that record number.
However, when i try this for the surname, which is very similar, it doesn't work:
cout << "\n\nPlease enter an associate surname :" << endl;
cin.getline(SearchName,NAME_LEN);
while((RecNum < MAX_QUOTES) && (SearchName != Quote[RecNum].Surname))
{
RecNum++;
}SearchName takes in the surname i enter along with some other stuff after it. I was wondering how to get rid of all the stuff after the surname to get this to work. I think its something to do with '/0' but that just stores up the remaining space with /0. It wont bring out the results for Snape as searchname is stored as Snape/0/0/0/0.
Any help would be great.
Ian
Last edited by iaaan; Feb 12th, 2007 at 2:01 pm.
It seems that you have declared searchnum as a C style string or a null terminated string. If you want to compare C style strings, you can't do it using the not equal to operator. You need to use the function [search]strcmp[/search] function which returns 0 when the two strings passed are equal.
Better yet, use C++ string class, accept the string using [search]getline[/search] and then use the != operator which is overloaded for the sake of effortless string comparision.
Better yet, use C++ string class, accept the string using [search]getline[/search] and then use the != operator which is overloaded for the sake of effortless string comparision.
Last edited by ~s.o.s~; Feb 12th, 2007 at 2:11 pm.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- using boolean expression on an array (Java)
- Problem installing XP on a SATA Striping Array (Storage)
- error 88:'(' expected when trying to display an array any help (Pascal and Delphi)
- Conver int Array into a String (Java)
Other Threads in the C++ Forum
- Previous Thread: urgently needed
- Next Thread: C++ const help
Views: 1162 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int integer java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






