Difference between r1.1 and the current
@@ -1,13 +1,71 @@
== 두 파일 동시에 열기 ==
{{{
}}}
== 두 파일을 각각 열기 ==
{{{
}}}
{{{
#include <stdio.h>
#include <string.h>
#pragma warning (disable: 4996)
int main(void)
{
FILE* pFile1, * pFile2;
pFile1 = fopen("data.txt", "r");
pFile2 = fopen("new.txt", "w");
char s[100];
if (pFile1 == NULL) perror("오류");
else
{
while (!feof(pFile1))
{
fgets(s, sizeof(s), pFile1);
fputs(s, pFile2);
}
}
fclose(pFile1);
fclose(pFile2);
return 0;
}
}}}
== 두 파일을 각각 열기 ==
{{{
#include <stdio.h>
#include <string.h>
#pragma warning (disable: 4996)
int main(void)
{
FILE* pFile;
pFile = fopen("data.txt", "r");
char str[100][100] = { NULL };
int i = 0;
if (pFile == NULL) perror("오류");
else
{
while (!feof(pFile))
{
fgets(str[i], sizeof(str) / sizeof(str[0]), pFile);
i++;
}
}
fclose(pFile);
pFile = fopen("new.txt", "w");
i = 0;
if (pFile == NULL) perror("오류");
else
{
while (str[i][0] != NULL)
{
fputs(str[i], pFile);
i++;
}
}
fclose(pFile);
return 0;
}
}}}
두 파일 동시에 열기 ¶
#include <stdio.h> #include <string.h> #pragma warning (disable: 4996) int main(void) { FILE* pFile1, * pFile2; pFile1 = fopen("data.txt", "r"); pFile2 = fopen("new.txt", "w"); char s[100]; if (pFile1 == NULL) perror("오류"); else { while (!feof(pFile1)) { fgets(s, sizeof(s), pFile1); fputs(s, pFile2); } } fclose(pFile1); fclose(pFile2); return 0; }
두 파일을 각각 열기 ¶
#include <stdio.h> #include <string.h> #pragma warning (disable: 4996) int main(void) { FILE* pFile; pFile = fopen("data.txt", "r"); char str[100][100] = { NULL }; int i = 0; if (pFile == NULL) perror("오류"); else { while (!feof(pFile)) { fgets(str[i], sizeof(str) / sizeof(str[0]), pFile); i++; } } fclose(pFile); pFile = fopen("new.txt", "w"); i = 0; if (pFile == NULL) perror("오류"); else { while (str[i][0] != NULL) { fputs(str[i], pFile); i++; } } fclose(pFile); return 0; }