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