LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-17-2003, 06:32 PM   #1
mymojo
Member
 
Registered: Oct 2003
Distribution: Slackware 9.1
Posts: 176

Rep: Reputation: 30
GCC - including <string.h> (won't work)


This is a sample program I'm running... see below for my problems

#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;
}

---

it says:

hello.cpp: In function `int main()':
hello.cpp:10: `strcmpi' undeclared (first use this function)
hello.cpp:10: (Each undeclared identifier is reported only once for each
function it appears in.)
hello.cpp:19: `strupr' undeclared (first use this function)
hello.cpp:22: `strlwr' undeclared (first use this function)

... so how do I install and use string.h, or what do I do?

using redhat9 with development ticked (no extra packages installed)
 
Old 10-17-2003, 06:35 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
the functions you are trying to use do not exist in the standard GNU C library... they are NOT in string.h in the first place.... where did you get this code from? C isn't always that portable
 
Old 10-17-2003, 06:42 PM   #3
mymojo
Member
 
Registered: Oct 2003
Distribution: Slackware 9.1
Posts: 176

Original Poster
Rep: Reputation: 30
http://www.cprogramming.com/tutorial/lesson9.html
 
Old 10-17-2003, 06:58 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
I actually found that site searching to answer your post.... pick a better site, one that uses proper ANSI C
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
in gcc compiler error: parse error before string constsnt cynthia_thomas Linux - Networking 1 10-20-2005 02:29 AM
dhclient shows IP, but internet including ping wont work mjkelly93 Linux - Networking 1 10-09-2005 08:46 AM
Replace a string including simple quotes. philipina Programming 4 03-18-2004 09:01 AM
java test if string in string array is null. exodist Programming 3 02-21-2004 02:39 PM
about STRING in gcc surya123 Programming 0 07-11-2003 10:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration