hi akshayakrsh
First of all Welcome to AO...........
Yes Trubo C++ will always give you this problem of not scanning the character variable if used just after some other variable in this faschion......it will just ignore it and go to the next statement .........it would have scaned the same value if it would have been the first value you have scanned .....i have no idea why.......apart from changing the compiler.......more simple solution i think is to use string %s it solves this problem...or specify the index number ch[0] where to store the value......that solves this problem........I had encountered this problem in the very early days of my learning C and at that time it got me soooo pissed ........because i just couldn't make out what the problem was ..........so so now that he has brought up the issue i would too like to know the reason if anybody knows........
If a few people didn't understand what akshayakrsh and i am trying to say here is look at the following code
In the following code it wouldn't even wait for me to put in the character value ....just after putting the number and pressing enter it would show the result wouldn't wait at the character............and the strange thing is i don't find anything wrong with this code........Code:#include<stdio.h> #include<conio.h> void main() { char ch; int num; printf("Enter Munber :"); scanf("%d",&num); printf("Enter character : "); scanf("%c",ch); printf("The Number you entered was : %d",num); printf("The Character you entered: %c",ch); getch(); Output The Number you entered was :12 }
If i input the number after the character it would work fine.......as in the following code
Code:printf("Enter character : "); scanf("%c",ch); printf("Enter Nunber :"); scanf("%d",&num);
The Solution to this is to use String instead of Character....
Or specify the erray location while entering the character ch[0]...Code:printf("Enter Munber :"); scanf("%d",&num); printf("Enter character : "); scanf("%s",ch);
Anybody have any idea why........![]()
And one thing more akshayakrsh........Some.People here generally don't appriciate bumping of very old threads until you have something useful to add......which i think you had here..........the thing is it is considered that if the thread is soo old the problem might have been solved by now.......If you have to post to a very old thread to add something to it.......... the Golden rule to Bump the thread first and then post ........keeps tham wondering...........just a word of advice i know this thread is not that old .
And i would like to suggest you would want to remove your Complete address from the location.....because you got the whole thing there with house Number With Pin Code......this being a public site you never know we got quite a few stakers around here j/k.........or are you Expecting Fan-mails
--Good Luck---




...........just a word of advice i know this thread is not that old .
Reply With Quote