#include <stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
FILE* fp;
char str[50], filename[50];
printf("字串:");
gets(str);
printf("檔案:");
scanf("%s", filename);
if ((fp = fopen(filename, "w") != NULL))
{
fputs(str, fp);
fclose(fp);
}
}
1>W:\C code\Project1\源.c(12,40): warning C4047: “=”:“FILE *”與“int”的間接級別不同
1>W:\C code\Project1\源.c(11,2): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>W:\C code\Project1\源.c(12,12): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>Project1.vcxproj -> W:\C code\Project1\Debug\Project1.exe
1>已完成生成專案“Project1.vcxproj”的操作。
========== 生成: 成功 1 個,失敗 0 個,最新 0 個,跳過 0 個 ==========
字串:hapy,happy
檔案:happy.txt
W:\C code\Project1\Debug\Project1.exe (行程 10044)已退出,代碼為 -1073741819。
按任意鍵關閉此視窗. . .
不知道是什么原因 ,自己也不會改求教
uj5u.com熱心網友回復:
if ((fp = fopen(filename, "w") != NULL))
改成如下:
if ((fp = fopen(filename, "w")) != NULL)
注意括號的位置。
因為!=的優先級高于=
uj5u.com熱心網友回復:
十分感謝你!每回都幫我解決問題!都不知道該怎么感謝你!uj5u.com熱心網友回復:
真丟人同樣的問題遭遇兩遍~!~~!uj5u.com熱心網友回復:
為什么txt檔案中一直什么都沒有

uj5u.com熱心網友回復:
改了那個問題之后,然后運行之后再去看你輸入的檔案
uj5u.com熱心網友回復:
??????
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/41192.html
標籤:C語言
上一篇:C++課程設計
下一篇:c語言遞回題
