here is the question
1. read in a first name, last name and telephone number
and store these in the list.
2. a search function that reads in a first name and last
name and searches the list for the name and prints
the phone number if found.
and the is what i did
so what my problem
there is no output
thanks
1. read in a first name, last name and telephone number
and store these in the list.
2. a search function that reads in a first name and last
name and searches the list for the name and prints
the phone number if found.
and the is what i did
Code:
#include <iostream> #include <cstring> using namespace std; struct pn { char fn[25]; char ln[25]; char pnbr[15]; struct pn *next; }; int main() { char t1[64], t2[64],t3[64]; struct pn *start=NULL, *p1,*p2,p3; while(1){ cin >> t1; if (strcmp(t1,"//")==0)break; cin >> t2 >> t3; p1 = new struct pn; if (p1 == NULL ) { cout << "memory error\n"; return 1; } strcpy(p1 -> fn,t1); strcpy (p1 -> ln,t2); strcpy(p1 -> pnbr,t3); p1->next = start; start = p1; } while(1){ cin >> t1; if ( strcmp(t1,"//")==0)break; cin >> t2; for (p1 = start; p1 != NULL; p1 = p1 -> next){ if ( strcmp(t1,p1 ->fn)==0) (strcmp( t2,p1 ->ln)==0); cout << "found b" << p1->pnbr << endl; break; } { if (p1== NULL) cout << "not found"; } return 0; } }
so what my problem
there is no output
thanks
Comment