본문 바로가기

공부/C언어

7.[C언어] 구조체 응용하기

728x90
반응형

0.파일

test.h
다운로드
소스.c
다운로드
소스2.c
다운로드

 

 

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_test);
    printf("test =%s\r\n", test);
 
    test2(&user_test_struct);
    init_arr(test,10);
 
}
 

 

2.test2.c

#include "test.h"
 
void test2(test_struct *user_test2)
{
    printf("high=%s\r\n", user_test2->high_test);
    printf("low =%s\r\n", user_test2->low_test);
}

 

3.test.h

#include <stdio.h>
 
 
typedef struct
{
    char high_test[20];
    char low_test[20];
}test_struct;
 
void test2(test_struct *user_test2);
 

4. 결과

 

728x90
반응형