728x90

프로그래머의 삶 Programmer's Life/C & C++ 51

리스트

#include"kyshdr.h" // stdio.h + stdlib.h +string.h #include #define RCSZ 80 #define OPEN(fp,fl,m) { if ((fp=fopen(fl,m))==NULL) { printf("Open %s 실패\n",fl); exit(5); } } /* 위의 마크로함수에서 '\'는 다음행으로 연결됨을 뜻함 */ typedef struct card_st CARD; //구조체 자료형을 선언 struct card_st { char name[16]; //성 명 char phon[16]; //전 화 CARD *next; // struct card_st *next; }; /* 함수원형 */ static int get_jno(); // 작업 번호 static i..

문자열 복사해서 비교..

#include #include main() { char s[80]; char str[80]; strcpy(s, "원섭 짱!!"); //s에 "원섭 짱"이라는 문자열을 복사. strcpy(str, "켜켜^^"); //str에 "켜켜^^"라는 문자열을 복사. if(!strcmp(s, str)){ //s와 str에 저장된 문자열을 비교하여 같으면 printf("두 문장이 일치합니다."); }else{ //같지 않으면.. printf("두 문장이 일치하지 않습니다."); } } =>결과 값은 당근 "두 문장이 일치하지 않습니다."가 뜨겠져^^

구조체

/* 구조체를 이용한 출력. */ #include void main() { struct person{ char name[10]; int age; int pay; }; struct person kim = {"김철수", 38, 562}; struct person leea = {"이영희", 22, 345}; struct person leeb = {"이영식", 41, 650}; printf("이름\t"); printf("연령\t"); printf("연소득(만원)\n"); printf("%s\t", kim.name); printf("%d\t", kim.age); printf("%d\n", kim.pay); printf("%s\t", leea.name); printf("%d\t", leea.age); printf(..

문자열 정렬

/* 임의의 문자를 알파벳 순으로 정렬하는 프로그램이다. 문자를 입력받는 것이 아니라 선언하였다. 또한 strcmp로 문자열을 비교하여 정렬하였다. */ #include #include void sort(char *p[], int n); void main(void) { int i=1, n; char str[] = "김영이, 이성호, 강인석, 황성현"; char delim[] = " \t\r\n,:\"'!~@#$%^&*()-_=+\\|.?/[]{};"; char *p[6]; p[0] = strtok(str, delim); //str배열을 delim배열을 기준으로 자른다. printf("%s\n",p[0]); while((p[i]=strtok(NULL, delim))!=NULL) { //문장이 끝날 때까지 ..

strcat, strncat함수 사용!!

=>strcat 함수 사용 #include #include main() { char s[30], str[30]; printf("문자열을 입력하시오: "); scanf("%s", &s); printf("문자열을 입력하시오: "); scanf("%s", &str); strcat(str, s); //str문자열에 s문자열을 붙여주는 함수가 strcat이져^^ printf("두 문자열을 연결하면 %s이다.\n", str); //s문자열이 str문자열에 붙으므로 str만 출려해주면 OK } =>strncat 함수 사용 #include #include main() { char s[30], str[30]; printf("문자열을 입력하시오: "); scanf("%s", &s); printf("문자열을 입력하시오: "..

728x90