Skip to content
Snippets Groups Projects
Commit 6caffd56 authored by choco5732's avatar choco5732
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
hello.c 0 → 100644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
// 파일 가져오기
FILE* pFile = fopen("test2.txt", "r");
if (pFile == NULL){
return 0;
}
int count = 0;
fscanf(pFile, "%d", &count); // 자바 : call by refernece, C : call by value
if (count == 0){
return 0;
}
// 텍스트의 값을 출력함 그 출력한 값을 다시 save 배열에 저장
int save[count+1]; // 이 배열 자체를 해시로 생각할 수 있어요
memset(save, 0, sizeof(save)); //memset : 지정한 값으로 배열을 한번에 초기화 해줌
int i = 0;
int num = 0;
int check = 0;
int save2 = 0;
// 1 1 2 3 4 5 1293812903810293218093
save[1] = 1;
save[2] = 0;
// 텍스트 파일의 값을 save배열에 저장
for(i = 0; i < count; i++){
fscanf(pFile, "%d", &num); // 입력 받은 num이 키인거죠
if (save[num]!=NULL){
check = 1;
break;
}
save[num]=num;
}
if(check==1){
printf("Incorrect. \n");
} else
printf("Correct\n");
fclose(pFile); // 파일 닫아줌으로써 쓰기 즉 저장이 됨 (중요)
return 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment