| | |
typed letters or numbers are reversed-"string"
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
0
#2 Oct 15th, 2009
Let's see...
No CODE tags, even thought there are at least 6 places they are explained, and 3 of them on the main page alone.
No explanation about why code was posted
I guess all there is to say is:
Congrats for writing some code! What's next?
No CODE tags, even thought there are at least 6 places they are explained, and 3 of them on the main page alone.
No explanation about why code was posted
I guess all there is to say is:
Congrats for writing some code! What's next?
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1
#3 Oct 16th, 2009
If you do not specify a return type for main(), it does not mean you are exempt from returning a value. This feature is called implicit int. It means that if a data type is expected but not provided, int is assumed. So these two definitions of main() are exactly the same and the return statement is required for both:
Relying on implicit int is not a good practice because the latest C standard removes the feature. Your code will not compile as C99, and that adds one more thing that needs to be changed to make it conform.
Names in all upper case are usually reserved for macros. It is up to you whether or not to use that convention, but people reading your code will be confused that STR1 is an array object and not a macro.
clrscr() is a non-standard function from conio.h, but you did not include conio.h. I would not recommend anything from conio.h, but like the naming conventions, it is up to you whether or not to take that advice. The portability police will not haul you away if you choose to use unportable stuff.
gets() is always unsafe and cannot be made safe through good coding practices. Never use it, because there is always a risk of array overflow. The safe alternative to gets() is fgets():
In C you should always make sure the output stream is flushed by either printing a line break or calling the fflush() function. It is possible that the output for your program will not show up before getch() starts waiting for input. It will look like the program is hanging. You can easily fix the problem and make the code work everywhere by printing a line break after the loop:
getch() is in the same category as clrscr() except there is a portable function from stdio.h that can replace getch() called getchar(). The only difference is that getchar() will probably not return until you type [Enter].
C Syntax (Toggle Plain Text)
main() { return 0; }
C Syntax (Toggle Plain Text)
int main() { return 0; }
Names in all upper case are usually reserved for macros. It is up to you whether or not to use that convention, but people reading your code will be confused that STR1 is an array object and not a macro.
clrscr() is a non-standard function from conio.h, but you did not include conio.h. I would not recommend anything from conio.h, but like the naming conventions, it is up to you whether or not to take that advice. The portability police will not haul you away if you choose to use unportable stuff.

gets() is always unsafe and cannot be made safe through good coding practices. Never use it, because there is always a risk of array overflow. The safe alternative to gets() is fgets():
C Syntax (Toggle Plain Text)
fgets(STR1, sizeof STR1, stdin);
C Syntax (Toggle Plain Text)
for(i=strlen(STR1)-1; i>=0 ; i--) { printf("%c",STR1[i]); } putchar('\n');
Last edited by Tom Gunn; Oct 16th, 2009 at 10:54 am.
-Tommy (For Great Justice!) Gunn
![]() |
Similar Threads
- How i can to generate characters of 'n' lenght using letters and numbers by rand() (C++)
- Letters, numbers and print numbers on the screen (C++)
- Hidden program installs .dlls with randomly generated names in random "notify" reg. (Viruses, Spyware and other Nasties)
- random letters/numbers (Visual Basic 4 / 5 / 6)
- my #include <string> wont make "string" bold (C++)
- google "keyword" question (Search Engine Optimization)
Other Threads in the C Forum
- Previous Thread: Problem with my Code
- Next Thread: C problems
Views: 414 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile csyntax directory drawing dynamic executable fflush file fork frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling scripting segmentationfault send shape socketprograming spoonfeeding stack standard string strings structures student suggestions systemcall testautomation unix user variable voidmain() wab win32 win32api windows.h






