C语言环境下的文件读写

目的:熟悉C的文件读写

环境:VC6.0++

补充:vc6.0库函数和头文件

代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 void test_write(void)
 5 {
 6     FILE *fp = NULL;
 7     char name[] = "mrsandstorm";
 8 
 9     fp = fopen("test.txt","w");
10 
11     if( fp == NULL)
12     {
13         printf("can't open the file");
14         return;
15     }
16 
17     if (fwrite(name, sizeof(char), strlen(name) ,fp) != strlen(name))
18     {
19         printf("file write error\n");
20     }
21     fclose(fp);
22 }
23 
24 void main(void)
25 {
26     printf("start.\n");
27     test_write();
28     printf("end.\n");
29 }

猜你喜欢

转载自www.cnblogs.com/mrsandstorm/p/9229285.html