LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-20-2005, 05:37 PM   #1
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889
Blog Entries: 1

Rep: Reputation: 30
Problem with test class pro, from C++ for dummies.


I have copied the following piece of code from c++ for dummies...

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string.h>
using namespace std;

class NameDataSet
{
public:
char firstName[128];
char lastName [128];
int creditCard;
};

bool getData(NameDataSet& nds);
void displayData(NameDataSet& nds);

int main(int nNumberofArgs, char* pszArgs[])
{
const int MAX = 25;
NameDataSet nds[MAX];

std::cout << "Read name/credit card information\n"
<< "Enter 'exit' to quit"
<< endl;
int index = 0;
while (getData(nds[index]) && index < MAX)
{
index++;
}

std::cout << "\Entries:" << endl;
for (int i = 0; i < index; i++)
{
displayData(nds[i]);
}

system("PAUSE");
return 0;
}

bool getData(NameDataSet& nds)
{
std::cout << "\nEnter first name:";
cin >> nds.firstName;

if (stricmp(nds.firstName, "exit") == 0)
{
return false;
}

std::cout << "Enter last name:";
cin >> nds.lastName;

cout << "Enter credit card number:";
cin >> nds.creditCard;

return true;
}

void displayData(NameDataSet& nds)
{
std::cout << nds.firstName
<< " "
<< nds.lastName
<< "/ "
<< nds.creditCard
<< endl;
}

... now, when I compile it with "g++ class.cpp -o class", I get the following message.

george@linux:~> g++ class.cpp -o class
class.cpp: In function `bool getData(NameDataSet&)':
class.cpp:47: error: `stricmp' undeclared (first use this function)
class.cpp:47: error: (Each undeclared identifier is reported only once for each
function it appears in.)
george@linux:~>

... I've been looking at the code, and I don't see where "stricmp" is located at in the code. I don't know if it is a function, or something that should have been declared (or initialized?) earlier in the program. I'm pretty confident that this is not an error in the authors wrighting, but then I be ignorant to believe that "I know".
 
Old 11-20-2005, 05:49 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
You need to include <cstring>, not <string.h>. Also, it is inconsistent in its usage of "using namespace std;". Either get rid of std:: everywhere, or put it in where nessecery and get rid of the using.
 
Old 11-20-2005, 05:58 PM   #3
Mistro116@yahoo.com
Member
 
Registered: Sep 2005
Posts: 118

Rep: Reputation: 15
Your gonna hit yourself when you see this:

It's a comparsion call...

It should probably be strgcmp(string 1, string 2);

Check line 47

Mistro116
 
Old 11-20-2005, 06:25 PM   #4
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889

Original Poster
Blog Entries: 1

Rep: Reputation: 30
I'm not sure what to do. What I wrote down is exactly what is showed. Line 47 is what is says. And I changed string.h to cstring. Still can't seem to get where I need to. I'll probably go on some online resource to find out how classes can be used. I have an idea, but I need to see it in action to fully understand it.
 
Old 11-20-2005, 06:54 PM   #5
FLLinux
Member
 
Registered: Jul 2004
Location: USA
Distribution: Fedora 9, LFS 6.3, Unbuntu 8.04, Slax 6.0.7
Posts: 145

Rep: Reputation: 15
It might be a typo. Try changing it from stricmp(string 1, string2) to strcmp(string1, string 2).
 
Old 11-20-2005, 08:03 PM   #6
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
instead of
Code:
stricmp(nds.firstName, "exit")
use
Code:
strcasecmp(nds.firstName, "exit")
I know I have saw stricmp or strcmpi used, maybe its in a win32 lib?? not sure, but there is not a man page for it in my distro....

oh by the way this did compile when I changed that line.
 
Old 11-21-2005, 11:08 AM   #7
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889

Original Poster
Blog Entries: 1

Rep: Reputation: 30
Alright, ty, I will try that as soon as I get home. Thanx again for the posts guys.
 
  


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
SUSE Linux 9.3 for Dummies (For Dummies S.) samuelmp SUSE / openSUSE 11 08-01-2005 01:42 PM
Implementing a vector class from a list class purefan Programming 9 04-14-2005 10:48 PM
BlackBox.class & VerifierBug.class virus ??? dalek Linux - Security 4 02-29-2004 08:55 AM
Inheriting class members (Qt C++, QApplication class) jtshaw Programming 2 01-15-2004 11:52 AM
c++ : regarding (inheritence)base class and derived class edreddy Programming 6 07-31-2002 06:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07: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
Open Source Consulting | Domain Registration