SMALL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | #include <stdio.h> #include <string.h> char input_name(char (*str1)[20]); int rep_check(char (*str1)[20], int cnt); void print_name(char (*str1)[20], int cnt); int main(void) { char name[10][20]; int cnt; cnt = input_name(name); print_name(name,cnt); return 0; } char input_name(char (*str1)[20]) { // char temp[10]; int cnt = 0; int i =0; int check; while(1) { printf("이름 : "); scanf("%s",str1[i]); if((strcmp(str1[i],"end")) == 0) { break; } cnt++; i++; check = rep_check(str1, cnt); if(check == 1) { i --; cnt--; } } printf("총 %d명이 입력되었습니다.\n",cnt); return cnt; } int rep_check(char (*str1)[20], int cnt) { int i,j; // char *str1[10]; int flag = 0; for(i = 0; i < cnt; i++) { for(j = i+1; j < cnt; j++) { if(strcmp(str1[i],str1[j]) == 0) { flag = 1; break; } } } if(flag == 1) { printf("# 이름이 이미 등록되어 있습니다.\n"); return 1; } return 0; } void print_name(char (*str1)[20], int cnt) { int i; for(i=0; i<cnt; i++) { printf("%s\n", str1[i]); } } | cs |
LIST
'개인자료 > 프로그래밍' 카테고리의 다른 글
임베디드 레시피 및 망고보드(Cortex M-3) 구입 (0) | 2015.05.29 |
---|---|
[임베디드 C] 비트 연산 매크로 (0) | 2015.05.17 |
[임베디드 C] 특정 비트 연산 (3) | 2015.05.17 |
[C언어] 인사말 정렬 프로그램 (0) | 2015.05.16 |
[C언어] 프로필 교환 프로그램 (0) | 2015.05.16 |
[C언어] 지점별 실적관리 프로그램 (0) | 2015.05.15 |
[C언어] 단어 추출 프로그램 (2) | 2015.05.15 |
[C언어] 전역 변수 교환 프로그램 (0) | 2015.05.15 |
[C언어] 단어 이어 출력하기 (0) | 2015.05.13 |
[C언어] 단어정렬 프로그램 (0) | 2015.05.13 |