QQ said:
Hello I have a string like this
"213200","0000","9999","204-033-105"
but I need to seperate them to be
s1 = 213200;
s2 = 0000;
s3 = 9999;
s4 = 204-033-105;
Is there any good way to do it?
Thanks a lot!
$ cat 1.txt
"213200","0000","9999","204-033-105"
#include <stdio.h>
#include <string.h>
int main()
{
FILE *fp;
char A[7]={0}, B[5]={0}, C[5]={0}, D[12]={0};
char StrFile[36];
int readStatus, LineNum = 0;
int i;
if((fp = fopen("1.txt","r")) == NULL)
{
fprintf(stdout,"\t File Reading Error\n");
exit(1);
}
else
{
readStatus = fscanf(fp,"%36s",StrFile);
printf("%d\n",readStatus);
while(readStatus == 1)
{
LineNum++;
memcpy(&A, &StrFile[1],6);
memcpy(&B, &StrFile[10],4);
memcpy(&C, &StrFile[17],4);
memcpy(&D, &StrFile[24], 11);
printf("A: %s B: %s C: %s D: %s \n", A,B,C,D);
readStatus = fscanf(fp, "%s",StrFile);
}
fprintf(stdout,"LineNumber is %d\n",LineNum);
}
return 0;
}