#include <stdio.h>
int main() {
// 打开要写入的CSV文件
FILE *csvFile = fopen("data.csv", "w");
if (csvFile == NULL) {
perror("Failed to open file");
return 1;
}
// 示例数据
const char *name1 = "Alice";
int age1 = 25;
const char *city1 = "New York";
const char *name2 = "Bob";
int age2 = 30;
const char *city2 = "Los Angeles";
// 写入数据行
fprintf(csvFile, "%s, %d, %s\n", name1, age1, city1);
fprintf(csvFile, "%s, %d, %s\n", name2, age2, city2);
// 关闭文件
fclose(csvFile);
printf("Data has been written to data.csv.\n");
return 0;
}
标签:const,int,写入,csvFile,C语言,char,csv From: https://www.cnblogs.com/yuyanc/p/17814424.html