코딩/Language Coder

630 : 파일입출력 - 자가진단5

pikapika 2020. 4. 29. 04:26

<코드>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	int len, n;
	char *arrs[100];
	char buf[100], x[5];
	char *tmp;
	
	fgets(x, 5, stdin);
	n = atoi(x);
	
	for(int i=0; i<n; i++)
	{
		fgets(buf, 100, stdin);
		len = strlen(buf);
		tmp = (char *)malloc(sizeof(char)*(len+1));
		strcpy(tmp, buf);
		arrs[i] = tmp;
	}
	
	for(int i=n-1; i>=0; i--)
	{
		fprintf(stdout, "%s", arrs[i]);
	}
		
	
	return 0;
}

 

※ N을 fscanf로 받으니까 자꾸 뒤에 개행문자가 문자열 배열에 들어가서 N을 문자열로 바꿔서 fgets로 입력받았다.