'(struct student *)&st' is a pointer; did you mean to use '->'?|

Viewed 210

screenshot

#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;
}

i wrote this code for a school project but codeblocks keeps giving me this error.Anyone know the solution? main.c|21|error: '(struct student *)&st' is a pointer; did you mean to use '->'?|

1 Answers

You cannot assign values in the same line where you are printing them, thats the whole problem

try this instead might work

st[i+1].srn

instead of

st[i].srn=i+1

The end code should look something like this

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;
}
Related