-1

I'm writing a phonebook application and one of the functions is for searching the phonebook by name.

The program should print out the names the same way as the user entered them (later I will include the numbers and other info). The phonebook has 100 contacts.

sname is the name that user have entered to search.

name[a] is name list. Is there any other code like strstr? Like its operating if its found printing them if not then print("not found any") something like this:

for(a=1; a<101; a++) {
    while(strstr(name[a],sname) != NULL) {
        printf(strstr(name[a], sname));
    }
}
Jason Aller
  • 3,541
  • 28
  • 38
  • 38

1 Answers1

0

You can do that: it is an infinite loop.

    while(strstr(name[a],sname)!=NULL){
        printf("%s\n",strstr(name[a],sname));
        }

None of a, name[a], sname change in the conditions or body of the while

pmg
  • 106,608
  • 13
  • 126
  • 198
  • should i change the place of FOR loop with that While loop ? – user3569411 May 11 '14 at 19:06
  • I think you want to replace the `while` with an `if`. The `for` loop appears to be at the correct place in the code structure (but it probably should start at `0`) – pmg May 11 '14 at 19:07