so I have an input file with a bunch of names and numbers. I started using strtok to split a row so that I can extract all the data from each row. It seems that everything is working correctly, but for some reason does not discard the newline character.
int procFile(PERSON **data, FILE* fpFile) { // Local Declaration char temp[1000]; char proc[15]; char *entry; char *loc; int success = 0; // Statement if(fgets(temp, sizeof(temp), fpFile)) { (*data) = aloMem(); // free entry = temp; loc = strtok(entry, " ()-"); strcpy(proc, loc); loc = strtok(NULL, " ()-"); strcat(proc, loc); loc = strtok(NULL, " ()-"); strcat(proc, loc); sscanf(proc, "%ld", &(*data)->phone); loc = strtok(NULL, "\0"); strcpy((*data)->name, loc); success++; printf("%s1", (*data)->name); } return success; }// procFile
I tried to print the results to make sure that it was working correctly, and this is my conclusion.
Brown, Joanne 1South, Frankie 1Lee, Marie 1Brown, Joanne 1Trapp, Ada Eve 1Trapp, David 1White, D. Robert 1Lee, Victoria 1Marcus, Johnathan 1Walljasper, Bryan 1Trapp, Ada Eve 1Brown, Joanne 1Andrews, Daniel
It prints 1 after each name on a new line, not the right after the name. Can someone explain to me how I can solve the problem?