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);

}

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);

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

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

No, just take the address of the structure member.

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

i cant get u!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.