用c语言写4、 创建文件,写入内容,输出结果 1) 在D盘创建一个文件“I have a dream.txt”; 2) 在该文件内,写入以下内容: I have a dream Martin Luther King I am happy to join with you today in what will go down in history as the greatest demonstration for freedom in the history of our nation. Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of their captivity. But one hundred years later, the Negro still is not free. 3) 打开该文件,将全部内容打印出来,关闭文件。
时间: 2023-12-10 12:40:41 浏览: 115
```c
#include <stdio.h>
int main() {
FILE *fp;
fp = fopen("D:\\I have a dream.txt", "w");
fprintf(fp, "I have a dream Martin Luther King I am happy to join with you today in what will go down in history as the greatest demonstration for freedom in the history of our nation. Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of their captivity. But one hundred years later, the Negro still is not free.\n");
fclose(fp);
fp = fopen("D:\\I have a dream.txt", "r");
char ch;
while((ch = getc(fp)) != EOF) {
putchar(ch);
}
fclose(fp);
return 0;
}
```
运行结果:
```
I have a dream Martin Luther King I am happy to join with you today in what will go down in history as the greatest demonstration for freedom in the history of our nation. Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of their captivity. But one hundred years later, the Negro still is not free.
```
阅读全文