Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在同一列中写入(csv文件)C_C_Csv - Fatal编程技术网

在同一列中写入(csv文件)C

在同一列中写入(csv文件)C,c,csv,C,Csv,我有一个问题,在csv文件中写入数据 数据保存在文件中,但都在同一列中 FILE *fichier = NULL; fichier = fopen("ville_secu_informatique_centroide.csv", "a"); fwrite((pVille + iVille)->Commune, sizeof(char) * 100, 1, fichier); fwrite((pVille + iVille)->CodeInsee, sizeof(char) * 100

我有一个问题,在csv文件中写入数据


数据保存在文件中,但都在同一列中

FILE *fichier = NULL;
fichier = fopen("ville_secu_informatique_centroide.csv", "a");
fwrite((pVille + iVille)->Commune, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->CodeInsee, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->url, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->Population, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->https, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->Serveur, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->Versionduserveur, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->Application, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->VersionApp, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->Langage, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->VersionLang, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->Latitude, sizeof(char) * 100, 1, fichier);
fwrite((pVille + iVille)->Longitude, sizeof(char) * 100, 1, fichier);
fclose(fichier);
我想在我的csv文件中的不同列中写入


感谢您的帮助

您需要在每两列之间写一个逗号,以获得逗号分隔的值。 另外,不需要使用“sizeof(char)”,它总是1。 此外,在写入文件时,请使用字符串的实际长度

例如:

fwrite((pVille + iVille)->Commune, strlen((pVille + iVille)->Commune), 1, fichier);
fwrite(",", 1, 1, fichier);
fwrite((pVille + iVille)->CodeInsee, strlen((pVille + iVille)->CodeInsee), 1, fichier);

输出逗号…“数据注册良好,”-o“真的吗?数据保存在文件中,但所有数据都在同一个冒号中。谢谢,这是功能性的