c文件读写

2024-09-28 11:22:04 50 Admin
互联网页模板

 

#include

 

int main() {

FILE *file_pointer;

 

// Open a file for writing

file_pointer = fopen("output.txt"

"w");

 

// Write 1000 characters to the file

for (int i = 0; i < 1000;="" i++)="">

fputc('a'

file_pointer);

}

 

// Close the file

fclose(file_pointer);

 

printf("Successfully wrote 1000 characters to the file.");

 

return 0;

}

 

In this code snippet

we first open a file called output.txt for writing using the fopen function. We then use a loop to write 1000 characters (in this case

the character 'a') to the file using the fputc function. Finally

we close the file using fclose and print a message to confirm that the characters were successfully written.

Copyright © 悉地网 2018-2024.All right reserved.Powered by XIDICMS 备案号:苏ICP备18070416号-1