언어/c언어

풀이 네이버

파아랑새 2017. 12. 18. 01:18

네이버 url

http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=290500575'

 

 

메모장 내용

1+1 =
2
2+2 =
4

====================================

 

// =============================
# include <stdio.h>
# include <stdlib.h> // atoi
# include <string.h>
# define ERROR 1
// =============================
int main(void) {
 FILE* fp = NULL;
 char strV[80] = { 0, };
 int ans = 0x0;
 int sel = 0x0;
 int resultNumber = 0x0;
 int i = 0x0;
 int j = 0x0;
 fp = fopen("C:\\Users\\sleep\\Documents\\Visual Studio 2013\\Projects\\ProJect\\TextFile1.txt", "r");
 //-------------------------
 if (fp == NULL) {
  printf("data.in open error !!\n");
  return ERROR;
 }
 else {
  // 문제
  // fp != NULL
  while (!feof(fp)) {
   fgets(strV, sizeof(strV), fp);
   resultNumber = atoi(strV);
   strV[strlen(strV) - 1] = '\0';
   if (j % 2 == 0) { // i가 홀수 일 때
    printf("[%d]번째 문제 : [%s] ", i + 1, strV);
    printf("답: ");
    scanf("%d", &sel);
    i++; // increase
   }
   else {
       // i가 짝수 일 때
    
    printf("resultNumber => %d\n", resultNumber);
    if (resultNumber == sel) {
     printf("정답 \n");
    }
    else {
     printf("틀림 \n");
    }
   }
   j++;
  }
 }
 fclose(fp);
 return 0;
}