I am reading a file line by line and splitting the string into tokens.
int main()
{
FILE* fp;
char line[255];
fp = fopen("file.txt" , "r");
while (fgets(line, sizeof(line), fp) != NULL)
{
char val1[16];
char val2[9];
strcpy(val1, strtok(line, ","));
strcpy(val2, strtok(NULL, ","));
printf("%s|%s\n", val1, val2);
}
}
My input file content (file.txt)
182930101222, KLA1512
182930101223, KLA1513
182930101224, KLA1514
182930101225, KLA1515
When I print get
| KLA1512
Instead of
182930101222| KLA1512
What is the issue ?