Reputation: 0 Apprentice
- Active Posts:
- 29 (0.03 per day)
- 27-September 11
- Profile Views:
- Last Active:
- Oct 23 2013 11:47 PM
- OS Preference:
- Who Cares
- Favorite Browser:
- Favorite Processor:
- Favorite Gaming Platform:
- Your Car:
- Who Cares
- Dream Kudos:
02 Oct 2011 - 21:44
Posts I've Made
Posted 23 Oct 2013
QuoteI don't wish to break the program in multiple functions and want to keep this design
QuoteWhy are you against using more functions?
Why would you want to keep your design, if it is a bad design?
I am not "against" it. I too like breaking my program into parts. Actually I am trying to finish the exercises of an old book on C. It uses quite outdated headers and functions of the time of Turbo C. I am just trying to stick to the way it teaches. Not to please anyone, but to see if I can make the programs that way too or not and with only those concepts that they taught in that book until that chapter.
QuoteSeveral things standout to me as very poor design issues. For example look at the following snippet:
fflush(stdin); printf("\nEnter the name of the Customer: "); gets(newCustomer.name);
There are at least two horrible design elements in this small snippet.
One fflush() is not designed to work with input streams.
Two gets() is a buffer overrun waiting to happen. You need to forget you ever heard about this function. Never use a function to retrieve a C-string that doesn't limit the number of characters it will retrieve.
You also need to check that your file actually opened properly and the read/write functions succeeded.
Actually if I don't use fflush, gets is unable to fetch the input. Even scanf fails for char arrays. If I use int array, it works fine. Moreover I wish to get more than one word stream, and I thought using the regular expression to get everything until encountering \n would be a bad idea since the book doesn't say anything about it. As I said, I was trying to stick to the minimal and old concepts it taught.
Next, about the gets() part, I know I didn't check array bounds, but I was careful in entering names that were <30 char long.
And won't the ferror would check the correct file opening? How can I check in some other way if possible?
I now think either I should try these programs on Turbo C only, else I will have to stop sticking to the book-things.
Thanks for your time though. Much appreciated sir!Why are you not checking the return values of remove() and rename(). If you check the return values and followup checking the errno variable, it would give you hints as to why the delete and rename are not working.
Okay, thanks. But from the code point of view, am I missing something? Or is it fine?
Posted 23 Oct 2013
Posted 23 Oct 2013I don't know if I have seen books on C++ better than the ones written by Robert Lafore and Bjarne Stroustrup
Posted 13 Jul 2012you said:
"select Afghanistan from StateList"; //if i use this instead it works!
If above works then, there is just one difference which is single quotations across Field Name remove these symbols from "dynamic" query and check again:
string statestr = "select " + Cntrylst.SelectedValue.ToString() + " from StateList";
Honestly, I was trying to solve this in the morning today and got it right(I hadn't read your reply till then). I just came here to tell that I did this and got it right and then saw that I have got the same reply from you already. It works completely fine now and yes your reply is correct. Thanks a lot for your time! Good Day friend!
Posted 12 Jul 2012
- Member Title:
- New D.I.C Head
- 21 years old
- August 9, 1992
- Programming Languages:
- C, C++, JAVA, ASP.NET, C#
- Website URL: