aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mycan.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/mycan.c b/mycan.c
index e534340..7fdef0c 100644
--- a/mycan.c
+++ b/mycan.c
@@ -89,30 +89,28 @@ int main(int argc, char **argv)
// check and fix corrupted .csv file
{
FILE * fp;
- char ch;
- uint32_t offset;
- int remain;
- if((fp=fopen(filename,"r"))==NULL)
+ if((fp=fopen(filename,"r"))!=NULL)
{
- fprintf(stderr,"Can't open file \"%s\".\n",filename);
- exit(1);
- }
- 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);
+ 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);
+ }
}
}