diff --git a/check.c b/check.c new file mode 100644 index 0000000000000000000000000000000000000000..e84f7164f48f360d9eafdee005a35694713514af --- /dev/null +++ b/check.c @@ -0,0 +1,71 @@ +#include +#include +#include + +#define MAX 151 + +int compare(const void *a, const void *b) // 오름차순 비교 함수 구현 +{ + int num1 = *(int *)a; // void 포인터를 int 포인터로 변환한 뒤 역참조하여 값을 가져옴 + int num2 = *(int *)b; // void 포인터를 int 포인터로 변환한 뒤 역참조하여 값을 가져옴 + + if (num1 < num2) // a가 b보다 작을 때는 + return -1; // -1 반환 + + if (num1 > num2) // a가 b보다 클 때는 + return 1; // 1 반환 + + return 0; // a와 b가 같을 때는 0 반환 +} + +int main(int argc, char* argv[]){ + + FILE* pFile = fopen("test22.txt", "r"); + if (pFile == NULL){ + return 0; + } + + char source[MAX] = { }; //문자열은 초기화 + char target[MAX] = { }; + + fgets(source, MAX, pFile); //첫 문자열 가져오기 + fgets(target, MAX, pFile); //두번째 문자열 가져오기 + printf("%s",source); // Dog fights. + printf("%s",target); // God fight. + + + // 대문자를 소문자로 바꿔서 둘을 비교해보자. + int i =0; + int source_length = strlen(source); + int target_length = strlen(target); + + for (i = 0; i < source_length; i++ ){ + if (source[i] >= 'A' && source[i]<= 'Z'){ + source[i] += 32; + } + } + for (i = 0; i < target_length; i++ ){ + if (target[i] >= 'A' && target[i]<= 'Z'){ + target[i] += 32; + } + } + + qsort(source, sizeof(source) , sizeof(source[0]), compare); + + for (i = 0; source_length; i++) + { + printf("%s ", source[i]); + } + + + +// if( strlen(source) == strlen(target) ){ +// printf("A valid anagram!\n"); +// } +// else{ +// printf("Error: The length of the two strings is different.\n"); +// } + + fclose(pFile); + return 0; +} \ No newline at end of file