본문 바로가기

공부/C언어

(36)
10. __VA_ARGS__ 의 쓰임 1. 사용 예 ) #include #define test1(...)printf(__VA_ARGS__); void main(){test1("test\n");} 2. 결과
9.[C언어] 구조체 typedef main.c #include struct test1 { int xpos; }; typedef struct { int ypos; }test3; int main(void) { struct test1 test2; test3 test4; test4.ypos; test2.xpos = 10; test4.ypos = 20; printf("%d\n",test2.xpos); printf("%d\n", test4.ypos); return 0; } typedef를 쓰면 struct를 생략하게 된다.
8.[C언어]공용체 사용하기_소수점 값을 HEX 로 바꾸기 0. 파일 1. main.c #include "test.h" union converter { float f_val; unsigned short u_val[2]; }; void main(void) { union converter user_conv; //user_conv.f_val = 23.30; user_conv.u_val[0] = 0x6666; user_conv.u_val[1] = 0x41BA; printf("%f\r\n", user_conv.f_val); printf("%X\r\n", user_conv.u_val[0]); printf("%X\r\n", user_conv.u_val[1]); printf("%d\r\n", sizeof(user_conv.u_val)); } 2. 결과 3. Hex 소수점 co..
7.[C언어] 구조체 응용하기 0.파일 1. main.c #include "test.h" char test[10] = "123456789/"; test_struct user_test_struct; void test_ham(){ int i = 0; for (i = 0; i < 5; i++) { user_test_struct.high_test[i] = test[i]; } for (i = 0; i < 5; i++) { user_test_struct.low_test[i] = test[i+5]; } } void main(void) { int i = 0; test_ham(); printf("high =%s\r\n", user_test_struct.high_test); printf("low =%s\r\n", user_test_struct.low_..
6.[C언어] 배열 초기화 하기 #include void user_init(char* init_test,int init_i) { int i = 0; for (i = 0; i
[c언어] 포인트 문자열 1. #include void main(void){char *test = "test"; printf("%s\r\n",test); }
5.[stm32f103][C언어] 구조체 응용하기(구조체 연결) 0. 파일 1. main.c #include "test.h" test1_handle test1; test2_handle test2; unsigned int main_a[2] = {0}; void main_test_init1(void) { test1.a = &main_a[0]; test1.b = 0; } void main_test_init2(void) { test2.Ins = &test1; test2.test2_val = 0; } void main_test1(test1_handle* user_test1) { user_test1->b = *(user_test1->a); //printf("%d\r\n", *(user_test1->a)); //printf("b=%d\r\n", user_test1->b); } v..
4.[stm32f103][C언어] 포인터 사용하기 1. test.h #include test2(unsigned int *test2); 2. main.c #include "test.h" void main(void) { unsigned int test=10; printf("test1=%d\r\n", test); test2(&test); printf("test2=%d\r\n",test); } 3. test2.c #include "test.h" test2(unsigned int *test2) { unsigned int *test2_ptr; test2_ptr = test2; *test2_ptr = 20; } 4. 결과