首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >'(struct student *)&st‘是一个指针;您的意思是使用’->‘吗?|

'(struct student *)&st‘是一个指针;您的意思是使用’->‘吗?|
EN

Stack Overflow用户
提问于 2020-12-13 13:34:15
回答 1查看 103关注 0票数 2

代码语言:javascript
复制
#include<stdio.h>
#include<string.h>
#define MAX 50

struct student
{
   int srn;
   char stu_name[30];
   char course[18];
   char addr[50];
};

int main()
{
    struct student st[MAX];
    int i;
    for (i = 0; i < MAX; i++)
    {
        printf("\nEnter name of the student %d : ", st[i].srn=i+1);
        scanf("%s", st[i].stu_name);
        printf("\nEnter course of the student %d : ", i+1);
        scanf("%s", st[i].course);
        printf("\nEnter address of the student %d : ", i+1);
        scanf("%s", st[i].addr);
    }
    for (i = 0; i < MAX; i++)
    {
        printf("\nname of student %d is %s", i+1, st[i].stu_name);
        printf("\ncourse is %s", st[i].course);
        printf("\naddr is %s", st[i].addr);
    }
    return 0;
}

我为一个学校项目写了这段代码,但代码块一直给我这个error.Anyone,知道解决方案吗?main.c|21|error: '(struct student *)&st' is a pointer; did you mean to use '->'?|

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-13 13:48:25

不能在打印的同一行中赋值,这就是整个问题所在

试着这样做可能会有用

代码语言:javascript
复制
st[i+1].srn

而不是

代码语言:javascript
复制
st[i].srn=i+1

结束代码应该如下所示

代码语言:javascript
复制
int main()
{
    struct student st[MAX];
    int i;
    for (i = 0; i < MAX; i++)
    {
        st[i].srn = i+1;
        printf("\nEnter name of the student %d : ", st[i].srn);
        scanf("%s", st[i].stu_name);
        printf("\nEnter course of the student %d : ", i+1);
        scanf("%s", st[i].course);
        printf("\nEnter address of the student %d : ", i+1);
        scanf("%s", st[i].addr);
    }
    for (i = 0; i < MAX; i++)
    {
        printf("\nname of student %d is %s", i+1, st[i].stu_name);
        printf("\nname of student %d is %s", st[i].srn, st[i].stu_name);
        printf("\ncourse is %s", st[i].course);
        printf("\naddr is %s", st[i].addr);
    }
    return 0;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65272666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档