fork download
  1. #include <stdio.h>
  2. char data[100][100];
  3. int col, line;
  4.  
  5. void read_csv() {
  6. FILE *fp = stdin; // or fopen("try.txt", "r");
  7. char ch;
  8. for(line=0;;line++) {
  9. for(col=0;;col++) {
  10. if(fscanf(fp, "\"%c\",", &ch) != 1) break;
  11. data[col][line] = ch;
  12. }
  13. if(col == 0) break;
  14. fscanf(fp, "%*[\n]");
  15. }
  16. }
  17.  
  18. int main() {
  19. read_csv();
  20.  
  21. // 1列名
  22. for(int i=0; i<line; i++) {
  23. printf("%c\n", data[0][i]);
  24. }
  25.  
  26. // 1行目
  27. for(int i=0; data[i][0] !=0; i++) {
  28. printf("%c", data[i][0]);
  29. }
  30. printf("\n");
  31.  
  32. // 3列名 2行目
  33. printf("%c\n", data[2][1]);
  34. }
  35.  
Success #stdin #stdout 0s 5284KB
stdin
"A","B","C","D","E","F","G",
"H","I","J","K","L","M","N",
"O","P","Q","R","S","T","U",
"V","W","X","Y","Z",
stdout
A
H
O
V
ABCDEFG
J