hi all, i was learning c++ for few months now but now i want to learn c first, i used eclipse juno for c++ learning and it worked perfectly. Since i'm learning C now i tried to do it in eclipse but i have issues with it. printf and scanf and other stuff. Any thoughts?
int number = 0;
printf("enter whole number! ");
printf("\nNumber you've entered is %d\n", number);
And this is the output I got ...
enter whole number! 25
Number you've entered is 25
Press any key to continue
If you aren't seeing that, then something else is wrong. By the way, had I compiled that as a C++ program using C++ compilation, i.e., used a *.cpp extension on my source code file instead of just C, I would have had exactly the same results. C++ includes C as a subset. Many of us compile as C++ but still use a lot of Cisms (depending on how successfully (or not)we've made the transmorgrification).
By the way, I hope you guys who work on embedded microcontrollers and such stuff with asm and c would improve your coding a bit! Last week I had to have the repair man down to look at my only one year old washing machine. It wouldn't start and appeared dead. Know what the repairman told my wife? Its computer locked up! We're talking here about my washing machine! Had to unplug it for a half hour to reset its computer. Then it worked. I think computers have gone too far. Blast the miserable beasts!!!
Welcome to Ironman receipt calculator
Total cost: 78.59$
Open new receipt? y/n y
Total cost: 57.60$
Open new receipt? y/n y
Total cost: 17.25$
Open new receipt? y/n n
Process returned 0 (0x0) execution time : 15.553 s
Press any key to continue.
The bottom line is that scanf is rather funky. You wouldn't want to sell a program that collects user input with scanf, and in fact, I'd be hesitant about even giving one away using it. In my opinion, its a bit more useful with files, i.e., fscanf. The issue involves stray characters in the keyboard input buffer, mostly.
The function blocks, and for a more professional console mode input experience I'd recomend the low level Win32 Console Mode Api functions.
All this code i'm writing is just an excercise to confirme what i've learnd in c++ before doing anything concrete. To see do i have solid grounds for c, logic and all other stuff, not so much about makeing some serious software at this point.
Theres no rush, im learning this as hobbiest, i figured since i've rounded the design sphere in past 14years going from graphics design all the way to industrial design, now i want to round the other sphere of interest, programing(c, c++, python, assembly), electronics and MCU) with focus on learning it right not fast;)
Ironman has already seen some of the irregularities of scanf. Its just fine for what he is doing in my opinion. But likely the irregularities he is seeing are the result of the things already mentioned. It might help to clean out the input buffer first wirh a getchar(). Then output a "Press Any Key To Continue...". There are various solutions. A lot of us have been dealing with these issues since early DOS days. I use scanf myself; just not much and not for anything where an actual user instead of a coder would be at the other end of it. Its quick and dirty, IMHO.
By the way IronmanCro, I just tried your program with %c instead of %s and far as I could tell it worked normally. That doesn't really mean it wasn't acting up for you though. What was it doing that was abnormal with %c (if you are still following your thread)?