Error with Lesson 9 of the tutorial

This is a discussion on Error with Lesson 9 of the tutorial within the C++ Programming forums, part of the General Programming Boards category; I was going through Lesson 9 of the tutorial here when it wouldn't compile. I thought I may have typed ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    3

    Question Error with Lesson 9 of the tutorial

    I was going through Lesson 9 of the tutorial here when it wouldn't compile. I thought I may have typed it in wrong, so I cut and pasted it and tried again. No dice.

    Here is the error I'm receiving:

    [sugapablo@localhost c++]$ g++ -o string2copy string2copy.cc
    string2copy.cc: In function `int main()':
    string2copy.cc:19: `strcmpi' undeclared (first use this function)
    string2copy.cc:19: (Each undeclared identifier is reported only once for each
    function it appears in.)
    string2copy.cc:37: `strupr' undeclared (first use this function)
    string2copy.cc:43: `strlwr' undeclared (first use this function)
    [sugapablo@localhost c++]$

    I'm really new at C++, but it I would guess perhaps it isn't including string.h? (I'm using the g++ compiler on Mandrake 8.2)



    Code:
    #include <iostream.h> //For cout
    
    #include <string.h> //For many of the string functions
    
    int main()
    
    {
    
      char name[50];            //Declare variables
    
      char lastname[50];        //This could have been declared on the last line...
    
      cout<<"Please enter your name: ";   //Tell the user what to do
    
      cin.getline(name, 50, '\n');       //Use gets to input strings with spaces or
    
    //just to get strings after the user presses enter
    
      if(!strcmpi("Alexander", name))  //The ! means not, strcmpi returns 0 for
    
      {                                //equal strings
    
        cout<<"That's my name too."<<endl; //Tell the user if its my name
    
      }
    
      else                              //else is used to keep it from always
    
      {                     //outputting this line
    
         cout<<"That's not my name.";   
    
      }
    
       cout<<"What is your name in uppercase..."<<endl;
    
      strupr(name);                   //strupr converts the string to uppercase
    
      cout<<name<<endl;
    
      cout<<"And, your name in lowercase..."<<endl;
    
      strlwr(name);                    //strlwr converts the string to lowercase
    
      cout<<name<<endl;
    
      cout<<"Your name is "<<strlen(name)<<" letters long"<<endl;  //strlen returns
    
    //the length of the string
    
      cout<<"Enter your last name:";
    
      cin.getline(lastname, 50, '\n'); //lastname is also a string
    
      strcat(name, " ");            //We want to space the two names apart
    
      strcat(name, lastname);      //Now we put them together, we a space in
    
    //the middle
    
      cout<<"Your full name is "<<name; //Outputting it all...
    
      return 0;
    
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    string2copy.cc:19: `strcmpi' undeclared (first use this function)
    string2copy.cc:37: `strupr' undeclared (first use this function)
    string2copy.cc:43: `strlwr' undeclared (first use this function)
    None of these are standard functions, and I'd guess your compiler doesn't support them. I'd suggest either looking in your compilers documentation to see if it has functions that do the same thing, but are called different names (for example stricmp() maybe available). Failing that, just write your own versions, which will be good practice for you.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    3
    Write my own versions? How would I do that? Anything on this site (or another) to show me how?

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You might also have this function


    >>Anything on this site (or another) to show me how?
    Yes, the FAQ is a good place to start
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    3
    Yes, I found strcasecmp while vi'ing string.h.

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My new website
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 03-17-2006, 07:38 PM
  2. Cprog tutorial: Design Patterns
    By maes in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2004, 02:41 AM
  3. Lesson 4 of Tutorial
    By polonyman in forum C++ Programming
    Replies: 5
    Last Post: 09-09-2004, 07:36 AM
  4. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  5. Problem with tutorial (Vector class)
    By OdyTHeBear in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2002, 02:49 PM

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