No strtok() hasn't been covered but that's a function i understand now because i looked it up in C reference on the net an it isn't that difficult
Originally Posted by itCbitC
So i understand you split the 3rd string into tokens where there's a space character.
There are some other things i don't quite get tho.
I specified everything i don't get with /* ????? */ in my comments so maybe u could have a look at my code and explane?
Here's my code:
I also would like to know how i can separate the first character i'm now putting in the bytes string to a new variable called dlc?
int main(int argc, char *argv) /* int main ?????????????? */
FILE *fpin, *fpout; /* declare input and output file pointer */
char flin, flout; /* declare input and output file name string */
char *s, line, x; /* declare pointer to ?????, and ????? */
char tijd, id, bytes; /* declare time, id and bytes string */
printf("This program converts standard Vector CANoe log files to Ecxel readable files\n\nPlease specify source filename:"); /* print programheader with programfunction and ask for input filename */
scanf("%s",flin); /* read input filename */
/* does inputfile exist ? */
if ((fpin = fopen(flin, "r"))== NULL) /* if can not open inputfile for reading */
printf("Cannot open source file!\n"); /* show cannot open input */
/* if inputfile does exist */
printf("Please specify destination filename:"); /* ask to specify destination filename */
scanf("%s",flout); /* read output filename */
fpout = fopen(flout, "w"); /* open outputfile for writing */
fprintf(fpout,"time\tid\tdlc\tbyte0\tbyte1\tbyte2\tbyte3\tbyte4\tbyte5\tbyte6\tbyte7\n"); /* print data header in outputfile */
while(fgets(line, 256, fpin)) /* while string from inputfile is ??????? */
if (sscanf(line, "%s%*s%s Tx %*s %[^\n]", tijd, id, bytes) == 3) /* ??????????? */
sprintf(x, "%s\t%s", tijd, id); /* print string time and id to file */
for ( s= strtok(bytes, " "); s; s = strtok(NULL, " ")) /* split bytes string into byteX when there's a space character */
sprintf(x, "%s\t%s", x, s); /* print ???? string to file */
fprintf(fpout, "%s\n", x); /* ??????????????? */
fclose(fpin); /* close inputfile */
fclose(fpout); /* close outputfile */
The output now is ok but the first characters that are put in the outputfile from the bytes string are actually the dlc data.
When i can ad this dlc variable in the code and put the first characters that are now in the bytes string in this dlc variable i have everything seperated like it should be.
then i can sprintf(x, "%s\t%s\t%s", tijd, id, dlc); and handle the bytes string in the same way i'm doing now.
Can you help me out with this?