-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFile.c
49 lines (39 loc) · 1.32 KB
/
File.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Created by jian on 2021/2/24.
//
#include <stdio.h>
int main222() {
FILE *fp;
fp = fopen("D:\\project_c\\ndk_demo\\test.txt", "w+");
//按读方式打开由argv[1]指出的文件
if(fp==NULL)
{
printf("The file <%s> can not be opened.\n",fp);//打开操作不成功
}
fprintf(fp, "This is testing for fprintf...\n");
fputs("This is testing for fputs...\n", fp);
fclose(fp);
printf("File :%s\n", __FILE__ );
printf("Date :%s\n", __DATE__ );
printf("Time :%s\n", __TIME__ );
printf("Line :%d\n", __LINE__ );
printf("ANSI :%d\n", __STDC__ );
FILE *fp2 = NULL;
char buff[255];
fp2 = fopen("D:\\project_c\\ndk_demo\\test.txt", "r");
if(fp2 == NULL)
printf("fail to open the file! \n");
else
{
printf("The file is open! \n");
fclose(fp2);
}
fscanf(fp, "%s", buff); //写入的时候和平常没有区别,还是只有字符串变量前不加‘&’,其他int、double等类型前都要加‘&’符号
printf("1: %s\n", buff);
fgets(buff, 255, (FILE *) fp); //scanf遇到空格就会断开,gets会读取空格,遇到换行就结束
printf("2: %s\n", buff); //255是限制最大读取内容长度
fgets(buff, 255, (FILE *) fp);
printf("3: %s\n", buff);
fclose(fp);
return 0;
}