--- title: "♾️ Чтение CSV на Си" date: 2023-06-05T22:08:07+03:00 draft: false tags: [c, tips] --- ## Файл CVS ```text id,text,from 1,text message,twitter 2,i live this language,book ``` ## Код ```c #include #include int main() { char buffer[80]; FILE *stream = fopen("example.csv", "r"); while (fgets(buffer, 80, stream)) { // Символ разделитель char *token = strtok(buffer, ","); // Если нам нужен только первый столбец каждой строки if (token) { printf("%s\n", token); } // Если нам нужны все значения подряд while (token) { printf("%s\n", token); token = strtok(NULL, ","); } } return 0; } ```