IT/프로젝트 및 실습 컴퓨터 프로그래밍 설계 과제#4_HW01 리드론 2017. 12. 12. 20:10 #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char **name; char *temp; int test_case, i, j; int check_flag=0; // 1이면 동일한 문자열이 있음, 0이면 없음 scanf("%d", &test_case); fflush(stdin); name = (char **)malloc((test_case)*4); // String의 주소값 배열 할당 //문자 배열 5개씩 동적할당 for (i=0 ; i<test_case ; i++) { name[i] = (char*)malloc((4+1)*sizeof(char)); // 내선번호의 뒷 4자리 scanf("%s", name[i]); } /* //내선번호 한개씩 출력 for (i=0 ; i<test_case ; i++) { printf("%s\n", name[i]); } */ //각 내선번호 뒷자리 중복 체크 for (i=0 ; i < test_case-1 ; i++) { for (j=i+1 ; j < test_case ; j++) { //printf("[%s] 비교 [%s]\n", name[i], name[j]); if(!strcmp(name[i],name[j])) { //printf("-----동일합니다-----\n"); check_flag = 1; break; } else { //printf("-----동일하지 않습니다-----\n"); } } if(check_flag==1){ break; } } if(check_flag==1){ printf("Duplicated\n"); } else { printf("No Problem\n"); } // 할당된 동적 메모리 해제 for (i = 0; i < test_case; i++) { free(name[i]); } free(name); return 0; } 저작자표시 변경금지