Thread: Useful program

  1. #16
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Quote Originally Posted by sean_mackrory
    And as for conio.h, the only problem is that it's non-standard. If you're distributing a commercial application, that's not a problem.
    I think all noobs shouldn't follow this rule, because a lot of rules makes programming really distasteful. Don't do THIS, do THAT, and then I get confused and I get depressed! Sometimes people who say: "Don't do this!" that don't even supply the solution for what to use without it. And that's ok, but it gets intense! It's hard being a learner :'(

  2. #17
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    However whiny one can be about it does not change the fact that it is nonstandard, and causes problems when asking for help and posting source code. It's not like there's a bunch of trolls going around beating up newbies for their lunch money and then telling them not to use conio.h and void main, etc... as they walk away. It's a fact, plain and simple.

  3. #18
    ---
    Join Date
    May 2004
    Posts
    1,379
    1. You shouldn't be using Turbo C anyway.
    2. gets() is a standard function, it is not in conio.h
    3. I'm not too familiar with what kbhit() does but I assume you can replace it with getchar()
    4. getch() should also be replaced with getchar()

    (in regards to 1.)
    Code:
    Disassembly of File: ascii.exe
    
    This file is not PE format ... sorry, it looks like DOS format
    *tsk* *tsk*
    Last edited by sand_man; 12-19-2004 at 10:43 PM.

  4. #19
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    1. You shouldn't be using Turbo C anyway.
    Yes, I find Dev-C++ much better. It's free and very common.

    2. gets() is a standard function, it is not in conio.h
    I'm not sure quite what you're replying to here... I'll just say that gets is standard, but the way it's generally used can run you into problems easily. Using fgets with stdin as your file pointer is a much better solution.

    4. getch() should also be replaced with getchar()
    Though it should be pointed out that getchar will wait until you press Enter, and IIRC, getch() will return on the first key pressed. It's a less desirable effect, but I still stand by the former arguments against it's use.

  5. #20
    ---
    Join Date
    May 2004
    Posts
    1,379
    I'm not sure quite what you're replying to here...
    i was replying to this
    Heck, if I didn't use gets I don't think I would need conio.h to begin with

  6. #21
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I'm not too familiar with what kbhit() does but I assume you can replace it with getchar()
    It returns true if a key has been hit, false if not

    Edit: More correctly if there is data in the input stream

  7. #22
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Quote Originally Posted by Kleid-0
    I think all noobs shouldn't follow this rule, because a lot of rules makes programming really distasteful. Don't do THIS, do THAT, and then I get confused and I get depressed! Sometimes people who say: "Don't do this!" that don't even supply the solution for what to use without it. And that's ok, but it gets intense! It's hard being a learner :'(

    i honestly appreciate people pointing out my mistakes and potential mistakes and why they are mistakes..i learn twice as much from one mistake than reading one chapter in "teach yourself c in16 seconds" or whatever my chosen text shall be....however, if someone does point out a mistake, but it's unrelated to my original problem and they offer no help with the original problem (or saying they don't know), then it does seem like nit picking...i understand though...but most noobs probably do not
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  8. #23
    Deleting... VOX's Avatar
    Join Date
    Oct 2004
    Location
    VA
    Posts
    94
    Thanks all you guys for your opinions on this. I now understand the difference between nit picking and constructive criticism. getchar() has replaced getch(), and getch is the reason I needed conio.h. Still solving the gets problem, though. Nothing wrong with Turbo C, it's old, but it works for everything I have done.

    Argh but that blinking cursor is bugging the hell out of me!
    Boy you stink, go take a shower before you continue to code. Better do your laundry and spray your chair too.

    The one and only resource for finding information.

    Next version of windows released!!!!

  9. #24
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    it works for everything I have done
    I'd bet you void main would work for everything you've done so far too... Just because it's worked before doesn't make it the right chouce. I do however, remember something about Turbo C being non-standard. Am I right, or am I confusing Turbo C with something else?

  10. #25
    ---
    Join Date
    May 2004
    Posts
    1,379
    just replace gets() with fgets()
    eg.
    Code:
    char code[3];
    int code2;
    
    gets(code);
    code2=atoi(code);
    
    /* The above would become... */
    
    char code[3];
    
    fgets(code,sizeof(code),stdin);
    Borland has always used non standard headers and non standard functions. Thats all I know.

  11. #26
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    I think he's just having a problem with getting a character rather than a whole string, but ya never know, here's another example:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main() {
    	// Get some input
    	char YourName[50];
    	fgets(YourName, sizeof(YourName), stdin);
    	printf("Your name is %s", YourName);
    }
    char *fgets(char *buffer, int size, FILE* stream);
    stdin would be the terminal stream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM