0

Why gets() or [^\n] is not working as expected in this program?

%s is working properly but specifiers in the question are not giving the expected result. https://code.sololearn.com/co6g31vRLrG8/?ref=app

30th May 2019, 2:54 AM
Deepak Chekuri
2 Respuestas
+ 3
it's working fine now, after some debugging, I don't want to create a code for it, just copy and run it #include <stdio.h> # include<string.h> typedef struct{ char city[20]; long int population; float literacy; }census; int main() { int i; census name[5],p[5],l[5]; for(i=0;i<5;i++) { printf ("\nenter name of city:"); scanf("%[^\n]",name[i].city); printf("\nenter population of city:"); scanf("%ld",&p[i].population); printf("\nenter literacy rate:"); scanf("%f",&l[i].literacy); } for(i=0;i<5;i++) { printf ("\nname of city:%s",name[i].city); // scanf("%[^\n]",name[i].city); printf("\npopulation of city:%ld",p[i].population ); // scanf("%l",&p[i].population); printf("\nliteracy rate:%f",l[i].literacy); // scanf("%f",&l[i].literacy); } return 0; }
30th May 2019, 8:22 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 1
Gets() works just fine but ^\n have problem running in sololearn because CLI isn't supported here so can't take \n as input Your code has got a lot of errors So check my gets() use https://code.sololearn.com/cWSAvZpjzHia/?ref=app
30th May 2019, 4:45 AM
Anurag
Anurag - avatar