MIPI_BaseC_WebinarFRTK/26_Seminar13/04_file_errors_p10.c

25 lines
598 B
C
Raw Permalink Normal View History

2024-11-13 09:22:28 +03:00
#include <stdio.h>
int main(int argc, char **argv)
{
FILE *open;
char name[] = "temperature_small2.csv";
open = fopen(name, "r");
if(open==NULL)
return 1;
int Y,M,D,H,m,T,n_scan;
while((n_scan = fscanf(open, "%d;%d;%d;%d;%d;%d", &Y, &M, &D, &H, &m, &T)) > 0)
{
if (n_scan < 6)
{
char s[20], c;
n_scan = fscanf(open, "%[^\n]%c", s, &c);
printf("Wrong format in line %s\n", s);
}
else
printf("%d = %d;%d;%d;%d;%d;%d\n", n_scan, Y, M, D, H, m, T);
}
fclose(open);
return 0;
}