0
#include<stdio.h>
#include<conio.h>
typedef struct Student
{
char nume[20],situatie[11];
int grupa,nr_credite;
} S;


void fct()
{ 
int n,i,c;
S st[100];

scanf("%d %d", &n, &c);

for(i=0;i<n;i++)
    scanf("%s %d %d", &st[i].nume, &st[i].grupa, &st[i].nr_credite);

for(i=0;i<n;i++)
    if (st[i].nr_credite>=n) st[i].situatie="Promovat";
                else st[i].situatie="Nepromovat";
}

int main()
{
fct();
return 0;
}

For the given code, this is the error I am getting.

Error: C:\Users\Rebekah\Downloads\e\main.c|20|error: assignment to expression with array type|

What am I missing here?

1
  • 1
    situatie is array of char. Instead of st[i].situatie="Promovat", use strcpy to copy string. Commented Jan 18, 2018 at 10:35

1 Answer 1

1
st[i].situatie="Promovat";

Array is not modifiable lvalue. So you can't do that. Use strcpy instead (when you know the size is big enough to hold the copied string).

strcpy(st[i].situatie,"Promovat");

Also check the return value of scanf.

if( scanf("%d %d", &n, &c) != 2 ){
    fprintf(stderr,"%s\n","Error in input");
    exit(EXIT_FAILURE);
}

Also another thing that you did wrong

scanf("%s %d %d", &st[i].nume, &st[i].grupa, &st[i].nr_credite);
                 ^^^

It will be

scanf("%s %d %d", st[i].nume, &st[i].grupa, &st[i].nr_credite);

st[i].name decays into pointer to char but the &st[i].name is of type char(*)[]. scanf's %s format specifier expects char*.

Compile the code like this gcc -Wall -Werror progname.c. Try to get rid of all warnings and errors.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.