Ok, I have a couple of questions on that...Originally Posted by fgw_three
1) What is the control string? Is it the string entered by the user or something else?
2) OK, so the whitespace characters (in this case the \n - I think - please tell me if I am wrong) are read by scanf()? ...And then discarded (does this mean ignored?)
Yeah, I wasn't aware of it at first because this course I am doing has been my only contact with C ever but, since hanging out here and checking various web sources, it seems to me that my teacher is actually teaching some functions that are not standard C (eg. fflush(stdin)) but he is not aware of it. I'm not sure why he doesn't realise this (the fact that he only programs under Windows may have something to do with it) or, as you say, maybe he hasn't spent much time actually coding lately because he has been teaching. Whatever the reason, it has certainly caused me problems not to mention a metric buttload of stress.Regarding your teacher, I'll offer a "Personal Opinion Fueled by Personal Bias" here...
Teachers are (for the most part in my experience) just that. They teach. In my experience, not that many of them have ever butted heads against code that needs to run on multiple platforms successfully, needing to be done on time, within budget etc etc. You learn a lot from living in that everyday programming environment, and teachers don't have that experience level.
My next class is tomorrow so I will raise it with him then. I'm not sure how he will respond but I hope he takes it constructivly and not as a critcism. In my experience, teachers don't appreciate being corrected by their students so I don't hold very high hopes for a good outcome no matter how respectfully I raise the issue.
If it turns out that he doesn't take it well, I may consider simply dropping the course and trying to study C on my own using the text books I have, web resources and advice from this forum. I hope it doesn't come to that though, there is really no substitute for the face to face tutoring you get with a proper teacher in a classroom.
The other thing that concerns me is that a few people have implied in this thread that there are other things in his code that, while not actually wrong, are bad practice or non standard. For example...
and...Is that code from the teacher? If you're teacher is teaching you fflush(stdin), then you should have that teacher reported to the school board. It's terrible code.
I must say that this is a bit worrying. I don't know enough to know what specifically is bad or why, but I am concerned that I may be being taught bad habits. This next one is particularly worrying...Well if he comes out with "void main" and using gets() to read input, then you'll know for sure that you have a bad'un.
These 3 things are the unholy trinity of the truly clueless.
...which seems to imply that I am being taught the incorrect (or at best non-standard or outdated) methods when other, better or more appropriate methods exist. I'm not sure if he will eventually cover the better methods or not but, even if he does, I have to wonder why we are being taught things that are frowned apon.Your problem is down to your teacher teaching "works for me C" rather than standard C. fflush(stdin) does something apparently useful for most DOS programmers, but is utterly useless for anyone else - it may do something, nothing at all, or something completely hostile to your system.
This is just the first example you have to deal with, god knows how many more horrors are in store. Best find a few online sources ( say here ) where you can verify everything your teacher says with people who have a clue.
The whole flushing issue goes away if you use fgets() to read a line of input, then sscanf() (or any other string conversion function) to convert that input into a form you want.
Yes, I will certainly do that. I have already gotten more solid information from this forum in less tha a week than I have gotten from my class in a full month and I am incredibly grateful for everyone's help. I was really starting to go under in class simply because I couldn't work out why the code (which I was assured was standard and cross platform) wasn't working on my Mac but was working for everyone else on PC.Please visit here often, and ask your questions. You will usually get a good, solid answer. We were all noobs at one point or another, and I can't speak for everyone else, but I had good mentors along the way, so I feel I should return the favor.
Thank you all for being so welcoming and supportive of nOObs such as myself. It is a phenomenon that does you credit as a group and it will certainly mean that I will be sticking around to ask and perhaps, one day even answer, questions.
Thanks! I think I need all the luck I can get at this stage.Good luck!