标题:输入输出学生信息,vc++6.0报错了,错误看不懂哩,求大神指教。
只看楼主
我就是我和你
Rank: 1
等 级:新手上路
帖 子:20
专家分:2
注 册:2013-4-4
结帖率:83.33%
已结贴  问题点数:20 回复次数:3 
输入输出学生信息,vc++6.0报错了,错误看不懂哩,求大神指教。
# include <stdio.h>
# include <malloc.h>

struct student
{
    int age;
    char name;
    float score;
};

int main(void)
{
    int len;
    struct Student * pArr;
    int i;
    //动态构造一维数组

    printf("请输入学生个数:\n");
    printf("len: ");
    scanf("%d", &len);
    pArr = (struct Student *)malloc(len * sizeof(struct Student));

    for (i=0; i<len; ++i)
    {
        printf("请输入第%d个学生信息:", i+1);
        printf("age: ");
        scanf("%d", &pArr[i].age);

        printf("name: ");
        scanf("%s", pArr[i].name);

        printf("score: ");
        scanf("%f", &pArr[i].score);
    }

    for (i=0; i<len; ++i)
    {
        printf("第%d个学生的信息是:\n", i+1);
        printf("age:%d\n", pArr[i].age);
        printf("name:%s\n", pArr[i].name);
        printf("score:%f\n", pArr[i].score);
    }

    return 0;
}
搜索更多相关主题的帖子: 信息 void include 动态 
2013-04-13 00:12
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
得分:5 
struct student
{
    int age;
    char name;
    float score;
};
struct Student * pArr;
结构体名字不匹配吧

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2013-04-13 07:43
果沫
Rank: 8Rank: 8
等 级:蝙蝠侠
帖 子:198
专家分:960
注 册:2013-1-30
得分:5 
C语言对大小写是敏感的
2013-04-13 09:03
a535182324
Rank: 2
等 级:论坛游民
帖 子:21
专家分:35
注 册:2013-3-5
得分:5 
// luntan.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"
#include "malloc.h"
#include "string.h"
//c语言中严格区分大小写,你的结构体名与声明时的不一致,都必须是大写
struct Student
 {
     int age;
     char name[2];//必须是字符数组的才能进行字符串的输出输入
     float score;
 };
 
int main(void)
 {
     int len;
     struct Student * pArr;
     int i;
     //动态构造一维数组
 
    printf("请输入学生个数:\n");
     printf("len: ");
     scanf("%d", &len);
     pArr = (struct Student *)malloc(len * sizeof(struct Student));
 
    for (i=0; i<len; ++i)
     {
         printf("请输入第%d个学生信息:", i+1);
         printf("age: ");
         scanf("%d", &pArr[i].age);
         printf("name: ");
         scanf("%s", pArr[i].name);
         printf("score: ");
         scanf("%f", &pArr[i].score);
     }
 
    for (i=0; i<len; ++i)
     {
         printf("第%d个学生的信息是:\n", i+1);
         printf("age:%d\n", pArr[i].age);
         printf("name:%s\n", pArr[i].name);
         printf("score:%f\n", pArr[i].score);
     }

    return 0;
 }
2013-04-13 09:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-404048-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.055735 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved