How can I get my last input (float) data in C? -
i input here example 101-name-3.4 3.4 not input. it's not showing in output. how can solve this?
for(i=0; i<n; ++i){ printf("enter id-name-cgpa receptively: "); scanf("%lld-%[^-]s-%f", id[i], name[i], cgpa[i]); }
you need remove trailing s
scanset directive in format string:
scanf("%lld-%[^-]-%f", id[i], name[i], cgpa[i]);
the s
not part of scanset directive, , scanf()
attempting, , failing, match s
in input. detected if code checking return value call scanf()
, practice.
also, no declarations shown, if id[]
declared array of long long int
s, , cgpa[]
declared array of float
s, address operator should used:
int ret_val = scanf("%lld-%[^-]s-%f", &id[i], name[i], &cgpa[i]); /* ret_val should 3 */
Comments
Post a Comment