0

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?

#include<stdio.h>

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


void inputStudent(stud std)
{
	printf("Enter student surname: \n");
	scanf("%s",std.surname);
	
	printf("Enter student other names: \n");
	scanf("%s",std.oname);
	printf("Enter address: \n");
	scanf("%s",std.address);
	printf("Enter age:\n");
	scanf("%d",std.age);
}


void  displayStudent(Stud std)
{
	printf("Surname:%s\n",std.surname);
	printf("Other Name:%s\n",std.oname);
	printf("Address:%s\n",std.address);
	printf("Age: %d \n",std.age);
}

void main()
{
	stud S1; 
	inputStudent(S1);
	displayStudent(S1);

}
2
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by techyworld
0

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.

example

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 by gerard4143: n/a

0

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

0

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?
0

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 by gerard4143: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.