Need help here. I am able to read a line of data, but I cannot break it up into tokens so that i can store them in an array.Code:#include <stdio.h>
typedef struct{
int id;
char name[30];
char address[30];
char phone[20];
int pid;
}Customer;
int main ( void )
{
Customer buyer[1000];
static const char filename[] = "c:/users/cyro/desktop/customer.txt";
FILE *file = fopen ( filename, "r" );
char *ptr;
int i =0;
if ( file != NULL )
{
char line [ 128 ]; /* or other suitable maximum line size */
while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
{
//fputs ( line, stdout ); /* write the line */
ptr = strtok(line," ");
while(ptr !=NULL)
{
//printf("%s \n",ptr);
char temp[30] ;
temp = &ptr;
fscanf("%d", &buyer[i].id);
strcpy(buyer[i].name, temp);
strcpy(buyer[i].address,temp);
strcpy(buyer[i].phone, temp);
fscanf("%d",&buyer[i].pid);
i++;
ptr = strtok(NULL," ");
}
}
fclose ( file );
}
else
{
perror ( filename ); /* why didn't the file open? */
}
return 0;
}