개인자료/프로그래밍
[임베디드 C] 특정 비트 연산
2015.05.1712345678 01010101 01010101OR 00100000 AND 11111011----------------------- ------------------------ 01110101 01010001 Colored by Color Scriptercs 1. 특정 비트 설정 1a |= 0x00100000;cs 0x0010_0000은 0x1(0x0000_0001)을 5번 왼쪽 시프트한 값과 같으므로 아래와 같이 표현 할 수 있다. 1a |= 0x1
[C언어] 인사말 정렬 프로그램
2015.05.161234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 #include #include void init_intro(char (*intro)[80], char **pint); // 2차원 배열과 포인터 배열 연결.int input_intro(char (*intro)[80]); // 인사말 입력void sort_intro(char **pint, int cnt); // 인사말 정렬void print_intro(int mode, void *vp..
[C언어] 프로필 교환 프로그램
2015.05.161234567891011121314151617181920212223242526272829303132333435363738394041424344454647 #include #include void swap(char *cp, void *vp1 , void *vp2); int main(void){ int age1, age2; double height1, height2; printf("첫 번째 사람의 나이와 키 입력 :"); scanf("%d%lf", &age1, &height1); printf("두 번째 사람의 나이와 키 입력 :"); scanf("%d%lf", &age2, &height2); swap("int", &age1, &age2); swap("double", &height1, &height2); pr..
[C언어] 방명록 프로그램
2015.05.1512345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485#include #include 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;}..
[C언어] 지점별 실적관리 프로그램
2015.05.15123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 #include void sales_avg(int *pa);void sort(char **sto_p, int **sal_p);void print_record(char **sto_p, int **sal_p);void print_store(char *store[4], int *sales[7]); int main(void){ char *store[4] = {"관악점", "강남점", "명동점", "대림점"};..
[C언어] 단어 추출 프로그램
2015.05.151234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859#include char *my_token(char *ps); int main(void){ char str[80]; char *p; printf("문장 입력 : "); gets(str); while((p = my_token(str)) != NULL) // 앞에서 부터 차례로 분리한 단어의 { // 포인터를 반환하여 출력한다 printf("%s\n", p); } return 0;} char *my_token(char *ps){ static char *next_location = NULL; // 정적 변수 사용. c..
[C언어] 전역 변수 교환 프로그램
2015.05.1512345678910111213141516171819202122232425262728293031323334353637383940#include void input_data(int *pa, int *pb);void swap_data(void);void print_data(int a, int b); int a, b; int main(void){ input_data(&a, &b); printf("두 정수 입력 : %d, %d", 10, 20); swap_data(); print_data(a,b); return 0;} void input_data(int *pa, int *pb){ *pa = 10; *pb = 20; }void swap_data(void){ int temp; temp = a; a = b; b = ..
[C언어] 단어 이어 출력하기
2015.05.131234567891011121314151617181920212223242526272829 #include #include int main(void){ char str[80] = ""; char temp[80] = ""; int i = 0; printf("input string : "); fgets(str,sizeof(str),stdin); str[strlen(str)-1] = '\0'; while((strcmp("end",str)) != 0) { strcat(temp, str); i = strlen(temp); temp[i] = 32; printf("current string : %s\n", temp); printf("input string : "); fgets(str,sizeof(str),stdin);..
[C언어] 단어정렬 프로그램
2015.05.131234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#include #include void swap(char *pa, char *pb);void line_up(char *max, char *mid, char *min); int main(void){ char str1[80], str2[80], str3[80]; scanf("%s%s%s",str1,str2,str3); // 문자열 3개 입력. line_up(str1, str2, str3); printf("%s, %s, %s", str1, str2, str3); return 0;} void swap(char *pa, char *pb){ ..
[C언어] 대소문자 변환 프로그램
2015.05.1212345678910111213141516171819202122232425262728293031 #include int main(void){ char ch; int res; // res = scanf("%c", &ch); while(res != -1) { scanf("%c",&ch); //ch = getchar(); // bit toggle if(((ch >= 'A') && (ch = 'a') && (ch = 'A') && (ch = 'a') && (ch
[C언어] 문자열 숫자 변환 프로그램
2015.05.121234567891011121314151617181920212223242526272829303132#include #include int main(void){ char num[11]; int ch; int i = 0,n; int sum = 0; int cnt = 1; int tot; while((ch = getchar()) != '\n') // 개행 문자가 나올 때까지 char 배열에 저장. { num[i] = ch; i++; } num[i] = '\0'; // 문자열의 끝을 알려주기 위해 널 문자 삽입. n = strlen(num); for(i = n-1; i >= 0; i--) // 변환된 값들의 자리 값 대입. { sum += ((num[i] - 48) * cnt); cnt *= 10; } tot ..
[C언어] 길이가 가장 긴 단어 찾기
2015.05.1212345678910111213141516171819202122#include int main(void){ char ch; int cnt = 0; int temp = 0; while((scanf("%c",&ch))!= -1) // Ctrl+Z가 입력시 종료 { if(ch != '\n') // ch가 개행 문자가 아닐 때 까지 카운트 증가. { cnt++; } else // 이전 단어와 입력한 단어의 길이 비교 { if(temp