#include #include #include #define MAX_LINE_LENGTH 100 int main() { FILE* file; char line[MAX_LINE_LENGTH]; char* context = NULL; // ファイルを読み込みモードでオープン if (fopen_s(&file, "sample.csv", "r") != 0) { printf("ファイルをオープンできませんでした。\n"); return 1; } if (file == NULL) { printf("ファイルをオープンできませんでした。\n"); return 1; } // データの読み込みと表示 while (fgets(line, MAX_LINE_LENGTH, file) != NULL) { // 改行文字を削除 line[strcspn(line, "\n")] = '\0'; // CSVデータをカンマで分割して表示 char* token = strtok_s(line, ",", &context); while (token != NULL) { printf("%s ", token); token = strtok_s(NULL, ",", &context); } printf("\n"); } // ファイルをクローズ fclose(file); return 0; }