+ 1
Whats wrong with this student structure code not working on mobile as well as conputer
#include<stdio.h> struct student { int rollno; char name[50]; int marks; }s[5]; int main() { int i; printf("Enter the Student data\n"); for(i=0;i<5;i++) { s[i].rollno=i+1; printf("For rollno %d\n",s[i].rollno); printf("Enter Name : "); scanf("%s",&s[i].name); printf("Enter Marks : "); scanf(" %d",&s[i].marks); } printf("Entered Students Data are :"); for(i=0;i<5;i++) { printf("Roll No %d\n",i+1); printf("Name : %s\n",s[i].name); printf("Marks : %d\n",s[i].marks); } }
1 ответ
+ 2
Got a warning when I ran the code, but only one problem was there, and it was the one also to cause of the warning (program compiles FYI).
scanf( "%s", s[ i ].name );
Here pass s[ i ].name without the address-of operator. I removed it and it works fine.
Are you running this in Code Playground or somewhere else? input is not interactive in Code Playground, and you must supply all necessary inputs in the beginning.