pm25_reader.c 560 B

123456789101112131415161718192021222324252627
  1. /** pm25_reader.c
  2. 读取 pm25 文件内容,按行输出内容
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. int main(int argc, char** argv){
  7. char *filename = "PM25_By_Cities.csv";
  8. FILE* fp = fopen(filename, "r");
  9. if(!fp){
  10. fprintf(stderr, "Cannot open file.\n");
  11. exit(1);
  12. }
  13. char *line = NULL;
  14. size_t linecap = 0; // line capacity
  15. ssize_t read;
  16. while ((read = getline(&line, &linecap, fp)) > 0)
  17. fwrite(line, read, 1, stdout);
  18. fclose(fp);
  19. if (line)
  20. free(line);
  21. return 0;
  22. }