0

whart is wrong with my code ?

#include<stdio.h> struct employee { char name[30]; char department[30]; char state[15]; char zone[25]; }; int main() { int i; struct employee e1[10]; for(i=0;i<10;i++) { printf("enter the name of employee = "); scanf("d",&e1[i].name); printf("Department = "); scanf("%d",e1[i].department); printf("State = "); scanf("%d",&e1[i].state); printf("zone = "); scanf("%d",&e1[i].zone); } }

23rd Oct 2020, 9:04 AM
Abhishek Kumar
Abhishek Kumar - avatar
5 Respuestas
+ 1
Your program giving soo many errors try to fix it. First thing you have not used format specifier properly . You taking Input chars and in scanf you wrote %d . %d use for decimal values not for string characters. Note that when you taking String as a input then in scanf & is optional u dont need ampersand operator. In printf statement you printing your message then u used scanf so it will take Input it won't print name zones .....states . i have tried to fix your bug you can use for loop for multiple input i removed .
23rd Oct 2020, 10:59 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
#include<stdio.h> struct employee { char name[30]; char department[30]; char state[15]; char zone[25]; }; int main() { struct employee e1[10]; printf("enter the name of employee = "); scanf("%s",e1->name); printf(" %s",e1->name); printf("\nDepartment = "); scanf("%s",e1->department); printf(" %s",e1->department); printf("\n State = "); scanf("%s",e1->state); printf(" %s",e1->state); printf("\nzone = "); scanf("%s",e1->zone); printf(" %s",e1->zone); }
23rd Oct 2020, 11:04 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Thanks
23rd Oct 2020, 9:29 AM
Abhishek Kumar
Abhishek Kumar - avatar
0
Also when use fgets()
23rd Oct 2020, 9:29 AM
Abhishek Kumar
Abhishek Kumar - avatar
0
Abhishek Kumar You can use fgets instead of scanf, but you would get even newlines into the strings.
23rd Oct 2020, 11:16 AM
Davide
Davide - avatar