More actions
No edit summary |
(Repair batch-0006 pages from live compare) |
||
| Line 11: | Line 11: | ||
pFile2 = fopen("new.txt", "w"); | pFile2 = fopen("new.txt", "w"); | ||
char s | char s[100]; | ||
if (pFile1 == NULL) perror("오류"); | if (pFile1 == NULL) perror("오류"); | ||
else | else | ||
| Line 37: | Line 37: | ||
FILE* pFile; | FILE* pFile; | ||
pFile = fopen("data.txt", "r"); | pFile = fopen("data.txt", "r"); | ||
char str | char str[100][100] = { NULL }; | ||
int i = 0; | int i = 0; | ||
if (pFile == NULL) perror("오류"); | if (pFile == NULL) perror("오류"); | ||
| Line 44: | Line 44: | ||
while (!feof(pFile)) | while (!feof(pFile)) | ||
{ | { | ||
fgets(str | fgets(str[i], sizeof(str) / sizeof(str[0]), pFile); | ||
i++; | i++; | ||
} | } | ||
| Line 55: | Line 55: | ||
else | else | ||
{ | { | ||
while (str | while (str[i][0] != NULL) | ||
{ | { | ||
fputs(str | fputs(str[i], pFile); | ||
i++; | i++; | ||
} | } | ||
| Line 64: | Line 64: | ||
return 0; | return 0; | ||
} | } | ||
Latest revision as of 01:08, 27 March 2026
두 파일 동시에 열기
#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;
}