1. c語言結構體如何循環輸入成員信息
#include<stdio.h>
structdate{
intyear;
intmonth;
intday;
};
structstudent{
intid;
charname[10];
charsex[10];
structdatebirthday;
};
intmain(){
inti;
structstudentstu[5];
for(i=0;i<5;i++){
printf("輸入第%d個學生學號,姓名,性別,生日 ",i+1);
scanf("%d%s%s%d%d%d",&stu[i].id,stu[i].name,stu[i].sex,
&stu[i].birthday.year,&stu[i].birthday.month,&stu[i].birthday.day);
}
printf("輸出第3個學生的信息: ");
printf("%d,%s,%s,%d,%d,%d",stu[3].id,stu[3].name,stu[3].sex,
stu[3].birthday.year,stu[3].birthday.month,stu[3].birthday.day);
return0;
}
這個是個簡單的實現,不知道對你有沒有幫助。
2. 新手求教!C語言中定義一組人員的信息,在後面添加其他人信息的時候怎麼判斷已有的編號里是否有該人信息
初始化的時候賦值0,之後判斷是否為0就知道是否已經添加過信息
3. 怎麼樣用C語言添加結構體信息 高手請進~~~~~``
struct student{
char name;
int number;
struct student *next;
}
這樣你定義了三個欄位,姓名,number
我不知道你為什麼這么定義,如果是我可能這么定義
struct student {
char name;/*學生姓名*/
int 性別; /*1代表femail (女性), 0 代表mail(男性)*/
int age;
struct student *next; /*為了用鏈表實現而採用*/
};
這樣完全可以實現你需要的數據類型.只需要再加上一些演算法就可以了.
如果還有什麼問題可以與我聯系.
一般工業上都會使用 typedef 來定義公司內部的統一定義如
typedef struct student {
};
4. c語言的成員到底是指什麼變數包括成員嗎
c語言中數據類型有整形,浮點,字元,雙精度,還有自定義類型結構體,數組,共用體等。 就拿結構體來說吧,它裡面可以包括很多數據類型的變數,如整形,浮點,字元,雙精度等, 每個變數都是他的成員。指針就是地址,指針變數就是用來保存地址的
5. c語言用鏈表添加學生信息
#include<stdio.h>
#include<string.h>
#include"stdlib.h"
#defineLENsizeof(structstu)
structstu
{
longnum;
charname[20];
charsex;
intage;
charaddr[30];
structstu*next;
};
intmain()
{
intn;
structstu*head;
structstu*p1,*p2;
head=(structstu*)malloc(LEN);
head->next=NULL;
p1=head;
p2=(structstu*)malloc(LEN);
p2->next=NULL;
printf("學號 姓名 性別 年齡 住址 ");
scanf("%ld, %s, %c, %d, %s",&p2->num,&p2->name,&p2->sex,&p2->age,&p2->addr);
while(p2->num!=0)
{
p1->next=p2;
p1=p2;
fflush(stdin);
p2=(structstu*)malloc(LEN);
printf("學號 姓名 性別 年齡 住址 ");
scanf("%ld,%s,%c,%d,%s",&p2->num,&p2->name,&p2->sex,&p2->age,&p2->addr);
}
}
純手打,希望採納。
6. c語言程序設計家庭財務報表,編寫成員信息錄入,錄入成員名字,序號,收入,支出,日期,用途等,求大神
圖片和標題要求不一致
7. c語言結構體 怎樣編才能 在運行中通過自己輸入,給成員賦值(該結構體有多個成員)
給你一個小例子:
#include<stdio.h>
struct Stu
{ char name[20];
int No;
int score;
};
main()
{ struct Stu student[10];
int i,
printf("輸入學生信息:\n");
printf("--------------------\n");
printf("姓名 學號 成績\n");
for(i=0;i<10;i++)
scanf("%s %d %d",student[i].name,&student[i].No,&student[i].score);
printf("輸出學生信息:\n");
printf("--------------------\n");
printf("姓名 學號 成績\n");
for(i=0;i<10;i++)
printf("%s %d %d",student[i].name,student[i].No,student[i].score);
}
滿意請採納!
8. C語言添加新成員信息
如果你是用結構體和鏈表的話,只要在鏈表裡面添加一條新的記錄,意思是說當鏈表頭結點為空時就添加到頭部,當鏈表不為空時接在鏈表的後面。
9. C語言中怎麼把文件中的數據賦到結構體的成員中
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 100 //宏定義SIZE
struct student
{
char name[SIZE];
char sex[10];
char age[10];
}stu;
int fread_line_txt(FILE *fp, char *buf) // 讀取文件中的一行
{
int i = 0;
while ((buf[i] = fgetc(fp)) != '\n')
{
i++;
if (i >= 99)
{
printf("SIZE lower! please alter SIZE\n");
return -1;
}
}
return i;
}
int cp_content (FILE *fp, char *buf, const char *name, char *dst) // 拷貝文件中指定內容 到字元串指針dst中
{
int i = 0;
char *p;
i = fread_line_txt(fp, buf);
buf[i] = 0;
if (p = strstr(buf, name))
{
memcpy(dst, p + strlen(name), strlen(p) - strlen(name));
}
return 0;
}
int main(void)
{
FILE *fp;
char buf[SIZE] = {0};
fp = fopen("1.txt", "r");
if (NULL == fp)
{
printf("fopen failed\n");
return -1;
}
memset((void *)&stu, 0, sizeof(struct student));
cp_content(fp, buf, "姓名:", stu.name);
memset(buf, 0, SIZE);
cp_content(fp, buf, "性別:", stu.sex);
memset(buf, 0, SIZE);
cp_content(fp, buf, "年齡:", stu.age);
printf("stu.name = %s, stu.sex = %s, stu.age = %s\n", stu.name, stu.sex, stu.age);
return 0;
}
//1.txt 應寫成這樣 要區分拼音和英文大小寫
#if 0
姓名:犀利哥
性別:男
年齡:十二歲
#endif