Question

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));
    }
}
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top