am having these error:

/home/Desktop/L3Q3.c: In function ‘inputStudent’:
/home/Desktop/L3Q3.c:23:2: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
/home/Desktop/L3Q3.c: At top level:
/home/Desktop/L3Q3.c:27:27: error: expected ‘)’ before ‘std’

Help please?


typedef  struct student
	char surname[20];
	char oname[20];
	char address[20];
	int age;

void inputStudent(stud std)
	printf("Enter student surname: \n");
	printf("Enter student other names: \n");
	printf("Enter address: \n");
	printf("Enter age:\n");

void  displayStudent(Stud std)
	printf("Other Name:%s\n",std.oname);
	printf("Age: %d \n",std.age);

void main()
	stud S1; 


If your scanf'ing a variable, you must use the address of the variable...If the variable name is an address(like character arrays) then you don't have to use the address of operator on it.


char my_str[] = "This is my string";
int x = 1234;

scanf("%s", my_str);//my_str is an array so no &
scanf("%d", &x);

Edited 5 Years Ago by gerard4143: n/a

so wat am i suppose to do? i try both with or without '&', it does not work!!

You have to start reading your error messages..

"warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’"

scanf("%d",std.age);//how do you make std.age an int pointer?

put this '%i' instead of "%d" ??

No, just take the address of the structure member.

scanf("%d",&std.age);//now your passing an int*

Edited 5 Years Ago by gerard4143: n/a

This article has been dead for over six months. Start a new discussion instead.