so i have a text file that goes like
cod1 last1, first1; 1 2 3
cod2 last2, first2; 1 2 3
.....
using fgets in a loop to read line by line and then put each variable into a structure type using sscanf
my structure type is
Code:
typedef struct
{
char code[5];
char *name;
int num[6];
}PERSON;
i was able to use sscanf just find to store cod1, cod2,... into char code but for some reason i can't get the name
Code:
while (i < 25) {
fgets(buffer, 99, file); //puts(buffer);
sscanf(buffer, "%4s", pChar[i].code);
printf("%s\n", pChar[i].code);
pBuff = buffer + strlen(pChar[i].code) + 1;
pChar[i].name = (char *)malloc(sizeof(char));
sscanf(pBuff, "%[^;] %*c", pChar[i].name); <----error
printf("%s\n", pChar[i].name);
i++;
}
i don't know what or how it went wrong and i've been looking back and forth but still don't get it ...
output gives error after the first loop and there're some weird characters
╨H>
cod1
last1, first1
cod2
Process returned 255 (0xFF) execution time : 8.192 s
Press any key to continue.