簡體   English   中英

使用字符串在c中打印到文本文件

[英]Printing to a text file in c using strings

我希望程序通過字符串將單詞hello打印到文本文件。

#include <stdio.h>

void main ()
{
    char word[10] = {"hello"};
    FILE*fp;
    fp = fopen("C:\\temp\\Dictionary.txt", "w+"); 

    fprintf(fp, word[0]);
}

您正在打印第一個char而不是字符串。 而且它也可能不是有效格式。 正確的調用將是fprintf(fp, "%s", word) 並且不要忘記關閉文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM