Can someone help me with these lines of codes?it gives me this error:
/home/Desktop/L3Q2.c: In function ‘main’:
warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’
/home/Desktop/L3Q2.c:19:2: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’
/home/Desktop/L3Q2.c:22:2: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’
/home/Desktop/L3Q2.c:28:2: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’
/home/Desktop/L3Q2.c:31:2: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’
/home/Desktop/L3Q2.c:34:2: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’


I use linux terminal to compile my C program.

#include<stdio.h>


int main()
{
	struct student
	{
	char surname[20];
	char oname[20];
	char address[20];
	int age;
	}stud1,stud2;

	
	printf("Enter student surname: \n");
	scanf("%s",&stud1.surname);
	
	printf("Enter student other names: \n");
	scanf("%s",&stud1.oname);

	printf("Enter address: \n");
	scanf("%s",&stud1.address);

	printf("Enter age:\n");
	scanf("%d",&stud1.age);

	printf("Enter student surname: \n");
	scanf("%s",&stud2.surname);
	
	printf("Enter student other names: \n");
	scanf("%s",&stud2.oname);

	printf("Enter address: \n");
	scanf("%s",&stud2.address);

	printf("Enter age:\n");
	scanf("%d",&stud2.age);


	if (stud1.age>stud2.age)
	{
		printf("Surname: %s \n", stud1.surname);
		printf("Other name: %s \n", stud1.oname);
		printf("Address: %s \n", stud1.address);
	}
	else if (stud2.age>stud1.age)
	{
		printf("Surname: %s \n", stud2.surname);
		printf("Other name: %s \n", stud2.oname);
		printf("Address: %s \n", stud2.address);
	}
	else
	{
		printf("Surname: %s \n", stud1.surname);
		printf("Other name: %s \n", stud1.oname);
		printf("Address: %s \n", stud1.address);

		printf("Surname: %s \n", stud2.surname);
		printf("Other name: %s \n", stud2.oname);
		printf("Address: %s \n", stud2.address);
	}
	return 0;

}

Try this

scanf("%s",stud1.oname);//remove the &

Now it gives me this error:

/home/Desktop/L3Q2.c: In function ‘main’:
/home/Desktop/L3Q2.c:25:2: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
/home/Desktop/L3Q2.c:37:2: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’

Put the & back for lines 25 and 37...I'm really getting the impression that your guessing about the implementation of scanf. I would try google scanf tutorial.

i restart my laptop and it works!thanks

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.