数据结构 —— 为结构体内变量赋值
生活随笔
收集整理的這篇文章主要介紹了
数据结构 —— 为结构体内变量赋值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
結構體內有int類型的變量,有char類型的變量,有float類型的變量。為該結構體內的變量賦值。
#include<stdlib.h> #include<stdio.h> #include<string.h> struct stu{int num;char name[20];char sex[20];float score; }boy1,boy2; int main(int argc, char **argv){boy1.num = 20;strcpy(boy1.name,"swj");printf("please input you sex and score!\n");scanf("%s %f",boy1.sex,&boy1.score);boy2 = boy1;printf("num\t|\tname\t|\tsex\t|\tscore\t|\n");printf("num=%d\t name=%s\t sex=%s\t score=%.3f\t\n",boy2.num,boy2.name,boy2.sex,boy2.score);return 0; }?操作文檔后結果顯示如下:
[root@J01051386 Test_20180418]# gcc struct.c [root@J01051386 Test_20180418]# ./a.out please input you sex and score! man 23.4 num | name | sex | score | num=20 name=swj sex=man score=23.400?
總結
以上是生活随笔為你收集整理的数据结构 —— 为结构体内变量赋值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Socket编程(C语言实现)—— Ng
- 下一篇: C 判断 —— switch语句(多个s