Thursday, July 30, 2009

How to read a char type structure member properly? the code below is not working properly.?

#include%26lt;stdio.h%26gt;


struct account


{


int accno;


char acctype;


char name_accholder[10];


float balance;


}s1,*pt;





main()


{


pt=%26amp;s1;





puts("enter accno type name of acc_holder balance");


scanf("%d%c%s%f",%26amp;pt-%26gt;accno,%26amp;pt-%26gt;acctype...


%26amp;pt-%26gt;name_accholder,%26amp;pt-%26gt;balance);





printf(" accno %d acctype %c name %s balance %f", pt-%26gt;accno,pt-%26gt;acctype,pt-%26gt;name_accholder...


}

How to read a char type structure member properly? the code below is not working properly.?
Do one thing try removing the "%26amp;" symbol from the scanf statement. Check if that is making any difference. I am doubting on that only.
Reply:scanf("%d %c %s %f" ,%26amp;pt-%26gt;accno,%26amp;p...








this will solve your problem the spaces between the formatters will help scanf to recognise the input correctly else it takes the last key stroke(enter key) as an input for %c and crashes.
Reply:Be clear in ur ques. Is the char acctype is not printed properly or the name_accholder array?





Let me know the output which you got...

free survey

No comments:

Post a Comment