我有三個數組,兩個ints另一個字符,我試圖將它們寫入一個文件。寫一個整數和字符數組到一個文件
我的做法是這樣的:
FILE *file;
char *allinfo=NULL;
int intArrayOne[7];
int *intArrayTwo=malloc(10*sizeof(int));
char *charArray=malloc(5*sizeof(char));
.....
write into the arrays
.....
if((file=fopen("filename", "a+"))==NULL)
printf("something went wrong\n");
else
{
asprintf(&allinfo, "%d%d%s", intArrayOne, intArrayTwo, charArray);
fprintf(file, "%s", allinfo);
fclose(file);
}
的問題,這似乎是整型數組不寫進allinfo字符串。 (asprintf函數順便分配內存,如果有人想知道的話)。那麼我怎麼能這樣高效地完成呢?