diff options
Diffstat (limited to 'mycan.c')
-rw-r--r-- | mycan.c | 43 |
1 files changed, 21 insertions, 22 deletions
@@ -87,31 +87,30 @@ int main(int argc, char **argv) //printf("this is a can receive demo\r\n"); // check and fix corrupted .csv file + for(FILE *fp;(fp=fopen(filename,"r"))!=NULL;) { - FILE * fp; - if((fp=fopen(filename,"r"))!=NULL) + char ch; + uint32_t offset; + int remain; + fseek(fp,-1L,SEEK_END); + fscanf(fp,"%c",&ch); + fseek(fp,0L,SEEK_END); + offset=ftell(fp); + //printf("csv file end offset: %d\n",offset); + fclose(fp); + remain=offset%ENTRY_SIZE; + if(remain) { - char ch; - uint32_t offset; - int remain; - fseek(fp,-1L,SEEK_END); - fscanf(fp,"%c",&ch); - fseek(fp,0L,SEEK_END); - offset=ftell(fp); - //printf("csv file end offset: %d\n",offset); - fclose(fp); - remain=offset%ENTRY_SIZE; - if(remain) - { - printf("Corrupted .csv file not a multiple of %d, removing last line\n",ENTRY_SIZE); - truncate(filename,offset-remain); - } - else if(ch != '\n') - { - printf("Corrupted .csv file last char not newline, removing last line\n"); - truncate(filename,offset-ENTRY_SIZE); - } + printf("Corrupted .csv file not a multiple of %d, removing last line\n",ENTRY_SIZE); + truncate(filename,offset-remain); + } + else if(ch != '\n') + { + printf("Corrupted .csv file last char not newline, removing last line\n"); + truncate(filename,offset-ENTRY_SIZE); } + else + break; } //1.Create socket |