Thread: need help with functions

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    3

    need help with functions

    here is my code. i am trying to write a simple program in which when the user's input is "monkey", my function adds the word "bars" to it. here is the code.

    #include <stdafx.h>
    using namespace std;

    int List(char word[250]);

    int main()
    {
    char word[250];

    cout << "Please enter the word 'Monkey': ";
    cin >> word;

    List(word);

    cout << "Here's the added suffix: " << word << "\n";


    return 0;
    }

    int List(char word[250] )
    {
    if (word == "monkey" || word == "Monkey")
    {
    word = strcat(word , "Bars");
    }
    return 0;
    }

    the program runs, but does not add "Bars". what is the problem

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can't compare character arrays using ==, nor can you assign them, using =. You either want to use the C++ string class, or use something like the strcmp to compare C style strings.

    While you're at it, go back and read the Announcements, and then post code next time with [code] tags.

    [edit]
    Lucky you, you're the recipient of my 4000th post.
    Well, 4000th for this incarnation of the C board anyway...
    [/edit]

    Quzah.
    Last edited by quzah; 07-07-2004 at 09:34 PM.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    3
    im sorry if it strained your eyes because i didnt put [code]

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It doesn't bother me. I'll either not bother taking the time to read your code, or I'll assume you write sloppy code. Either way, it only hurts you, not me.

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM