C/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
#include <stdio.h>
 
int main() {
  FILE *in, *out;
  char str[255];
 
  if((out = fopen("str.txt","w")) == NULL) {
    printf("Can't open file!!");
    exit(1);
  }
 
  fscanf(stdin, "%s", str);
  fprintf(out, "%s", str);
  fclose(out);
 
  if((in = fopen("str.txt","r")) == NULL)   {
    printf("Can't open file!!");
    exit(1);
  }
 
  fscanf(in, "%s", str);
  fprintf(stdout, "%s\n", str);
  fclose(in);
}
cs


C/C++ 언어 문자 입력 받아서 파일에 저장하고 화면에도 출력

+ Recent posts