Repository navigation
Expand file tree
/
Copy pathtest.cpp
More file actions
160 lines (142 loc) · 2.41 KB
/
Copy pathtest.cpp
File metadata and controls
160 lines (142 loc) · 2.41 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#include<stdio.h>
#include<stdlib.h>
#include"contect.h"
#include<memory.h>
int main()
{
FILE* fpIn = fopen("D:\\软件工具\\fff.jpeg", "rb");
if (NULL == fpIn)
{
printf("open file1 fail\n");
return 0;
}
FILE* fpOut = fopen("D:\\fff.jpeg","wb");
if (NULL == fpOut)
{
printf("open file2 fail\n");
fclose(fpIn);
return 0;
}
char buf[128];
size_t count = 0;
while (!feof(fpIn))
{
count=fread(buf, sizeof(char),128, fpIn);
fwrite(buf, sizeof(char),count,fpOut);
}
fclose(fpIn);
fclose(fpOut);
system("pause");
return 0;
}
#if 0
int main(int argc,char *argv[])
{
FILE * fpIn = fopen("test.cpp", "r");
if (NULL == fpIn)
{
printf("open file1 fail\n");
system("pause");
return -1;
}
FILE * fpOut = fopen("D:\\test2.txt", "w");
if (NULL == fpOut)
{
printf("open feile2 fail\n");
fclose(fpIn);
system("pause");
return -1;
}
char buffer[128];
memset(buffer, 0, sizeof(buffer));
char *ret =fgets(buffer,128,fpIn);
// printf("buffer=%s\n", buffer);
while (ret != NULL)
{
fputs(buffer, fpOut);
memset(buffer, 0, sizeof(buffer));
ret = fgets(buffer,128,fpIn);
}
fclose(fpIn);
fclose(fpOut);
system("pause");
return 0;
}
#endif
#if 0
int main()
{
FILE * fpIn = fopen("D:\\测试文件\\test1.txt", "r");
if (NULL == fpIn)
{
printf("open file1 fail\n");
system("pause");
return -1;
}
FILE * fpOut = fopen("D:\\test.txt", "w");
if (NULL == fpOut)
{
printf("open feile2 fail\n");
fclose(fpIn);
system("pause");
return -1;
}
char ch = fgetc(fpIn);
while (ch != EOF)
{
fputc(ch, fpOut);
ch = fgetc(fpIn);
}
fclose(fpIn);
fclose(fpOut);
system("pause");
return 0;
}
#endif
#if 0
int main()
{
int arr[10];
int n = sizeof(arr) / sizeof(arr[0]);
FILE * fp1 = fopen("D:\\测试文件\\test1.txt", "r");
//FILE * fp2 = fopen("D:\\test2,txt", "r");
if (NULL == fp1)
{
printf("open file fail\n");
return 0;
}
for (int i = 0; i < n; ++i)
{
fscanf(fp1, "%d", &arr[i]);
}
for (int i = 0; i < n; ++i)
{
printf("%d ", arr[i]);
}
fclose(fp1);
system("pause");
return 0;
}
#endif
#if 0
int main()
{
int arr[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int n = sizeof(arr) / sizeof(arr[0]);
FILE* fp = fopen("D:\\测试文件\\test2.txt", "a");
if (NULL == fp)
{
printf("open file fail\n");
return 0;
}
for (int i = 0; i < n; ++i)
{
fprintf(fp, "%d ", arr[i]);
}
fclose(fp);
system("pause");
return 0;
}
#endif