|  |
| |
| prosthetics |
한문자씩 읽어서 char buffer[]에 저장하고
만약 문자가 '\n'이라면 buffer에 담긴 문자열을 원하는 문자열 배열에 담아 주시면 됩니다. |
2011/11/25 |
|
| prosthetics |
참고로 확인해보니
fgets는 띄어쓰기로 구분하는것이 아니라 MAX_COUNT(최대로 읽어올 문자수)만큼 읽어오네요.
#include <stdio.h>
#define LINE_SIZE 512
void main()
{
char buffer[LINE_SIZE];
FILE *output = fopen("a.txt","w");
FILE *input = fopen("a.txt","r");
fprintf(output,"S P A C E\n");
fclose(output);
fgets(buffer,LINE_SIZE,input);
printf("%s",buffer);
fclose(input);
} |
2011/11/25 |
|
| prosthetics |
예제 입니다.
#include <stdio.h>
/*
LINE_SIZE : 한줄의 크기
LINE_COUNT : 총 줄의 개수
*/
#define LINE_SIZE 512
#define LINE_COUNT 100
void main()
{
/*필요한 변수 선언*/
char line[LINE_COUNT][LINE_SIZE];
char tmp;
int i = 0;
int n = 0;
int j;
FILE *output = fopen("a.txt","w");
FILE *input = fopen("a.txt","r");
/*a.txt에 문자열 저장*/
fprintf(output,"S P A C E\n");
fprintf(output,"띄 어 쓰 기\n");
fclose(output);
/*파일의 끝까지 \n을 기준으로 line에 문자열 저장*/
while(true)
{
if(fscanf(input,"%c",&tmp)==-1)//EOF
break;
if(tmp =='\n')
{
line[n][i] = tmp;
line[n][i+1] = NULL;
n+=1;
i=0;
}
else
{
line[n][i++] = tmp;
}
}
/*line에 저장된 값 출력*/
for(j = 0; j<n; j++)
{
printf("%s",line[j]);
}
fclose(input);
} |
2011/11/25 |
|