Im a newb help!

This is a discussion on Im a newb help! within the C++ Programming forums, part of the General Programming Boards category; i thought conio.h was a borland specific library...

  1. #16
    ---
    Join Date
    May 2004
    Posts
    1,379
    i thought conio.h was a borland specific library

  2. #17
    Registered User
    Join Date
    Jun 2004
    Posts
    20
    sand_man, hmm, not sure about conio.h but it does work with only conio.

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by sand_man
    i thought conio.h was a borland specific library
    They're not talking about including a header file, they're talking about including a .c file. A poor way to do it, but I suppose if one feels the need to mix input types... :cringe:

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #19
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >getche(); can also be used, if your program ends as soon as the functions are over.
    Let's not introduce nonstandard things when the OP is so confused with the standard ones, kay?

    >#include <conio> (on borland)
    That would be <conio.h>.

    >#include <conio.c> (on dev and others)
    That's generally a bad idea.
    My best code is written with the delete key.

  5. #20
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Because the idea is to compile your .c / .cpp files, and include header files. It's what I like to call "bad form". It's ugly.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #21
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >anybody care to tell me why including .c files is a bad idea?
    .c files routinely define things, and multiple definitions are illegal. Including a .c file will probably work if you only do so once and don't define any names that it defines, but doing so is tricky and error prone and considered very bad form.
    My best code is written with the delete key.

  7. #22
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >except if you place your code inside #ifndef right?
    That's akin to putting a Band-Aid over a gunshot wound. It might work, but is it really addressing the right problem?
    My best code is written with the delete key.

  8. #23
    Registered User
    Join Date
    Jun 2004
    Posts
    52
    Thank you guys. I understand what went wrong. I really appreciate all of the help and when i code some more I'll put it up if i have any problems. One problem im havin right now is this. Can if/else statements handle things such as names.

    example:
    If I wanted to code something that asked for somones name and have it check whether it registers with the program or not. If it does register u can continue, otherwise the program ends. I tried writing one of these but I wasnt able to get it to work at all. So I was wondering if if/else was the right thing to use. Thanks!

  9. #24
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by XSquared
    Put the code of the e() function above main(), or use a prototype above main:
    Code:
    int e();
    They could have also put the prototype in main.

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #25
    1479
    Join Date
    Aug 2003
    Posts
    253
    Quote Originally Posted by Siggy
    Can if/else statements handle things such as names.

    example:
    If I wanted to code something that asked for somones name and have it check whether it registers with the program or not. If it does register u can continue, otherwise the program ends. I tried writing one of these but I wasnt able to get it to work at all. So I was wondering if if/else was the right thing to use. Thanks!
    A Switch statement would be a lot better function for you to use for this task.
    Knowledge is power and I want it all

    -0RealityFusion0-

  11. #26
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    The most common mistake for noobies to make here is this:
    Code:
    char InputName[64];
    
    cin >> InputName;
    
    if (InputName=="Bennyandthejets") //This line is incorrect
        cout << "You are bennyandthejets!" << endl;
    else
        cout << "I don't know you" << endl;
    The problem with the above-marked line is that you are not comparing the content of 'InputName' with the string "Bennyandthejets". You are actually comparing the location of each element. They will never be in the same location, so the code will output "I don't know you". In order to compare the elements correctly, you need the function lstrcmpi(). It compares two strings and returns 0 if they are the same. So, this is how you rewrite the above code:
    Code:
    if (lstrcmpi(InputName,"Bennyandthejets")==0)
        cout << "You are Bennyandthejets!" << endl;
    else
      // etc etc
    So a simple way to complete your problem would be to compare the inputted string with a number of constant strings like so:
    Code:
    if (lstrcmpi(InputName,"benny")==0)
        GoIntoProgram();
    if (lstrcmpi(InputName,"siggy")==0)
        GoIntoProgram();
    
    ExitProgram();
    So the name entered must be 'benny' or 'siggy' for the program to continue. That is a simple way of doing it. There are nicer and more complicated ways of doing it too, but you'd best save that for later.

    A Switch statement would be a lot better function for you to use for this task.
    What do you base this statement on? Strings are messy with switch statements. This is how I do it:
    Code:
    #define IDS_LOAD 101
    #define IDS_SAVE 102
    #define IDS_QUIT 103
    #define IDS_UNKNOWN 104
    
    int ReturnStringNumber(char *TheString)
    {
    	if (!lstrcmpi(TheString,"load"))
    		return IDS_LOAD;
    	if (!lstrcmpi(TheString,"save"))
    		return IDS_SAVE;
    	if (!lstrcmpi(TheString,"quit"))
    		return IDS_QUIT;
    
    	return IDS_UNKNOWN;
    }
    
    int main()
    {
    	char InputString[64];
    
    	cin >> InputString;
    
    	switch (ReturnStringNumber((char *)InputString))
    	{
    		case IDS_LOAD:
    		case IDS_SAVE:
    		case IDS_QUIT:
    		case IDS_UNKNOWN:
    	}
                     return 0;
    }
    See what I mean?
    Last edited by bennyandthejets; 06-30-2004 at 06:55 AM.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  12. #27
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >In order to compare the elements correctly, you need the function lstrcmpi().
    This isn't a standard function. As such, not all implementations are guaranteed to have it, and even if the OP's implementation does have it, the code won't be portable. On top of that, lstrcmpi has different results than might be expected due to special treatment of certain nonalphabetic characters. Better to either use strcmp, strncmp, or use the C++ string class (preferable) for now.
    My best code is written with the delete key.

  13. #28
    Registered User
    Join Date
    Jun 2004
    Posts
    52
    Thank you guys but I already wrote the program yesterday. You can can see the thread
    " My name program" for how i did it. Any replies as to how I could have done it otherwise should go there and I would really appreciate it if you would!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question Character Counting
    By Wilder in forum C Programming
    Replies: 13
    Last Post: 06-22-2008, 11:37 PM
  2. Dogpile the newb!
    By lindy in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 05-23-2008, 08:17 AM
  3. Total newb directx invisable geometry question
    By -pete- in forum Game Programming
    Replies: 5
    Last Post: 08-13-2006, 01:45 PM
  4. Newb C++ Programmer
    By Philandrew in forum C++ Programming
    Replies: 8
    Last Post: 10-19-2004, 08:44 PM
  5. if your not newb you can help me
    By Klinerr1 in forum C++ Programming
    Replies: 6
    Last Post: 05-05-2002, 12:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21