1.30.作业.(未完善)

作业:

定义学生结构体属性:姓名,年龄,分数,输入姓名key查找key是否出现,存在则输出所有信息,否则提示查找失败要求:使用typedef

1,定义函数连续在堆区申请空间2,定义函数循环输入

3,定义函数实现输出3,定义函数实现查找4,释放空间

head.h

#ifndef __head_h__
#define __head_h__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct
{
    char name[16];
    int age;
    float score;
//    mess no;
}stu1,*stu2;
/*typedef union
{
    int mess1[10];
    int mess2[10];
}mess;*/
stu2 Prace(int n);
void Input(stu2 p,int n);
void Output(stu2 p,int n);
//char getkey(stu2 p,int n);
char look(stu2 p,int n);

#endif

text.c

#include"head.h"
stu2 Prace(int n)
{
    stu2 p=(stu2)malloc(sizeof(stu1)*n);
    if(NULL==p)
    {
        return NULL;
    }
    else
    return p;
}
void Input(stu2 p,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        printf("输入姓名\n");
        scanf("%s",(p+i)->name);
        printf("输入年龄\n");
        scanf("%d",&(p+i)->age);
        printf("输入成绩\n");
        scanf("%d",&(p+i)->score);
    }

}
void Output(stu2 p,int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        printf("姓名:%s 年龄:%d 成绩:%d \n",(p+i)->name,(p+i)->age,(p+i)->score);
    }
}
/*char getkey(stu2 p,int n)
{
    int i,key[15];
    printf("输入名字\n");
    scanf("%s",key);
    for(i=0;i<15;i++)
    {
        if(key[i]!='\0')
        {
            return k
        }
        return key[i]
    
    }
}
*/

char look(stu2 p,int n)
{
    int i,count;
    char q[15];
    scanf("%s",q);//输入查找
    for(i=0;i<n;i++)
    {
        if(strcmp(q[0],(p+i)->name)==0)
        {
            count++;
            printf("%s  %d  %d\n",(p+i)->name,(p+i)->age,(p+i)->score);
        }
    }
    if(count)
    {
        printf("%d\n",count);
    };

}





mian.c

#include "head.h"
int main(int argc, const char *argv[])
{
    int n=5;
    char key[16];
    //借空间
    stu2 p=Prace(n); 
    //输入
    Input(p,n);
    //输出
    Output(p,n);
    //查找
    printf("请输入查找名字\n");
    //key[]=getkey(p,n);
    printf("%c",look(p,n));
    //释放
    free(p);
    p=NULL;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值