/*広告*/

/*[C言語]サンプルプログラム集 入れ替えソース3*/

/*目次へ戻る*/

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> struct STUDENT{ char name[128]; int age; }; struct STUDENT set_data(const char* , int); void my_swap2(struct STUDENT* ,struct STUDENT* ); int main(){ struct STUDENT student[2]; int i; student[0] = set_data("tanaka",15); student[1] = set_data("suzuki",12); for(i=0;i<2;i++){ printf("%d:%s %d\n",i,student[i].name,student[i].age); } my_swap2(&student[0],&student[1]); printf("\n"); for(i=0;i<2;i++){ printf("%d:%s %d\n",i,student[i].name,student[i].age); } return 0; } struct STUDENT set_data(const char* name, int age){ struct STUDENT tmp; strcpy(tmp.name,name); tmp.age = age; return tmp; } void my_swap2(struct STUDENT* a,struct STUDENT* b){ struct STUDENT tmp; tmp = *a; *a = *b; *b = tmp; }

/*ページの先頭へ*/

/*目次へ戻る*/

/*HOME*/

/*Copyright 2016 K.N/petitetech.com*/

/*広告*/