문제

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));
    }
}
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top