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