I'm having this weird error when I pass in a structure array to a function to read it from file, but it keeps giving wrong output.
Code:void process(int command, char *argc[]) { struct Contact contact[CONTACTSIZE]; int size = readSaved(contact); printf("%s %s %s %s\n", contact[0].first, contact[0].last, contact[0].home, contact[0].cell); if(command == 1 || command == 2) search(command, argc[2], contact, size); else if(command == 3) { delete(argc[2], argc[3], contact, size); size--; Save(contact, size); } else { add(command, argc[2], argc[3], argc[4], contact, size); size++; Save(contact, size); } }the output should be something like this: Tom Johnson 333-444-5555 111-222-3333Code:int readSaved(struct Contact contact[]) { FILE *fp; int max = 2*NAMELENGTH + 2*PHONELENGTH; char line[max], *token; int i = 0; if((fp = fopen(FILENAME, "r")) != NULL) { while(fgets(line,max, fp) != NULL) { token = strtok(line, " "); contact[i].first = token; token = strtok(NULL, " "); contact[i].last = token; token = strtok(NULL, " "); contact[i].home = token; token = strtok(NULL, "\n"); contact[i].cell = token; i++; } fclose(fp); } return i; }
but it keeps giving me this: space space space space.
this is bothering me for a long time and I cannot find where went wrong??
Can I get some help on this?
thanks



LinkBack URL
About LinkBacks


