답안 #16304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
16304 2015-08-20T10:56:04 Z who7117 뚊 (kriii3_EE) C
컴파일 오류
0 ms 0 KB
#include<stdio.h>
#include<string.h>
#define MAX 100

int compare(char*, char*, int);        
int _input(int, int);

void main()
{
	unsigned int N, M, result;
	char eyfa[MAX], eeyfa[MAX];
	char eyfa2[MAX], eeyfa2[MAX];

	scanf("%d %d", &N, &M);		// N : stage      M : eyfa size
	
	while (N > 0)
	{
		fflush(stdin);
		fgets(eyfa, M + 2, stdin);		// why +2?
		eyfa[strlen(eyfa) - 1] = '\0';			// '\n' change

		fflush(stdin);
		fgets(eyfa2, M + 2, stdin);		// why +2?
		eyfa2[strlen(eyfa2) - 1] = '\0';			// '\n' change

		fflush(stdin);
		fgets(eeyfa, sizeof(eeyfa), stdin);
		eeyfa[strlen(eeyfa) - 1] = '\0';

		fflush(stdin);
		fgets(eeyfa2, sizeof(eeyfa2), stdin);
		eeyfa2[strlen(eeyfa2) - 1] = '\0';

		result = compare(eyfa, eeyfa, M);
		if (result == 0) printf("Eyfa");
		else printf("Not Eyfa");
		printf("\n");

		result = compare(eyfa2, eeyfa2, M);
		if (result == 0) printf("Eyfa");
		else printf("Not Eyfa");
		printf("\n");

		N--;
	}
}
int compare(char *str1, char *str2, int M)
{
	int cnt = 0;

	for (int i = 0; i < M; i++)
	{
		for (int y = cnt; cnt < y + 2; cnt++)
		{
			if (str1[i] != str2[cnt]) return 1;
		}
	}
	return 0;
}

Compilation message

ee.c:8:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 void main()
      ^
ee.c: In function ‘compare’:
ee.c:51:2: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
  for (int i = 0; i < M; i++)
  ^
ee.c:51:2: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
ee.c:53:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
   for (int y = cnt; cnt < y + 2; cnt++)
   ^
ee.c: In function ‘main’:
ee.c:14:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);  // N : stage      M : eyfa size
  ^
ee.c:19:3: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
   fgets(eyfa, M + 2, stdin);  // why +2?
   ^
ee.c:23:3: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
   fgets(eyfa2, M + 2, stdin);  // why +2?
   ^
ee.c:27:3: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
   fgets(eeyfa, sizeof(eeyfa), stdin);
   ^
ee.c:31:3: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
   fgets(eeyfa2, sizeof(eeyfa2), stdin);
   ^