I have created a linkedlist. Sent the linkedlist to a file with a write and read option. I am stuck with with load function. I am also 2 months new to C and a noob to this site.
My Code:
void load( char filename[10], struct node *np){
// creating a temporary variable for holding a record
char tmpfirstName[30];
char tmplastName[30];
char tmpPhoneNo[15];
char tmpeMail[55];
char tmpAddress[255];
int counter;
// declare a file pointer
FILE *input= fopen(filename, "r+");
//check if the file opened successfully
if (input==NULL)
perror ("Error opening file");
else{
counter=0;
// continue in reading the file till the EOF
while(!feof(input)){
strcpy(tmpfirstName," ");
fscanf(input, "%s %s %s %s %s -=", tmpfirstName, tmplastName, tmpPhoneNo, tmpeMail, tmpAddress);
if(strcmp(tmpfirstName," ")!=0){
strcpy(np->[counter].firstName, tmpfirstName);
strcpy(np->[counter].lastName, tmplastName);
strcpy(np->[counter].phoneNo, tmpPhoneNo);
strcpy(np->[counter].eMail, tmpeMail);
strcpy(np->[counter].address, tmpAddress);
counter++;
}
}
fclose(input);
}
The errors I am getting:
C:\Users\User\Documents\Pelles C Projects\FinalProject\PhoneBook.c(134): error #2047: Expected a field name.
C:\Users\User\Documents\Pelles C Projects\FinalProject\PhoneBook.c(135): error #2047: Expected a field name.
C:\Users\User\Documents\Pelles C Projects\FinalProject\PhoneBook.c(136): error #2047: Expected a field name.
C:\Users\User\Documents\Pelles C Projects\FinalProject\PhoneBook.c(137): error #2047: Expected a field name.
C:\Users\User\Documents\Pelles C Projects\FinalProject\PhoneBook.c(138): error #2047: Expected a field name.