Delete words error!!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2004
Posts: 65
Reputation: koh is an unknown quantity at this point 
Solved Threads: 0
koh koh is offline Offline
Junior Poster in Training

Delete words error!!

 
0
  #1
Sep 7th, 2004
I've just wrote this program and when i compile, there is an error at the red color fonts.
Can i know what's the error?
thank you.

char quest;
char words[50];
int count;
int z;
ofstream file;
file.open("WORDS.txt" , ios::app);
file.close();

cin.ignore(50,'\n');
cout << "\n\n Please enter the word that need to be deleted: ";
cin.getline(words,50,'\n');

for (int i=0; i<strlen(words); i++)
{
words[i]= tolower(words[i]);
z = count + 5;

}

for (i=0; i < count; i++)
{
if ( strcmp( words[i],words) == 0 )
z = i;
}



if (z<count)
{
ofstream file;
file.open("WORDS.txt", ios::app);

for ( i=0; i < count; i++)
{
if ( i!=z )
cout << words[i] << endl;
}


system("del words.txt");
system("ren words.txt words.txt");
}
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Delete words error!!

 
0
  #2
Sep 7th, 2004
ah it's simple, just do for(int i=0; i<.......

A for loop has it's own scope so you have to declare the i again.
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 8
Reputation: DoubleShot is an unknown quantity at this point 
Solved Threads: 0
DoubleShot DoubleShot is offline Offline
Newbie Poster

Re: Delete words error!!

 
0
  #3
Sep 7th, 2004
Variable z and count are never initialized. You should start with int z=0 and int count=0. When you get into the loop, count is an unknown value
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 23
Reputation: iamboredguy is an unknown quantity at this point 
Solved Threads: 0
iamboredguy's Avatar
iamboredguy iamboredguy is offline Offline
Newbie Poster

Re: Delete words error!!

 
0
  #4
Sep 7th, 2004
Did you include string.h?
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 23
Reputation: iamboredguy is an unknown quantity at this point 
Solved Threads: 0
iamboredguy's Avatar
iamboredguy iamboredguy is offline Offline
Newbie Poster

Re: Delete words error!!

 
0
  #5
Sep 7th, 2004
No wait. You are trying to compare individual letters with strings when you use
words[i]. strcmp() can only accept string arguments.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 65
Reputation: koh is an unknown quantity at this point 
Solved Threads: 0
koh koh is offline Offline
Junior Poster in Training

Re: Delete words error!!

 
0
  #6
Sep 7th, 2004
yes..

this one was just a part of my program.
just can't figure out the problem...
error message says:
error c2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char*'

..but then, i didn't use pointers
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 91
Reputation: gusano79 is on a distinguished road 
Solved Threads: 7
gusano79 gusano79 is offline Offline
Junior Poster in Training

Re: Delete words error!!

 
0
  #7
Sep 8th, 2004
The second parameter to strcmp up there is actually a pointer--that's half of what an array is, just a location in memory (the other half is the field size, in this case char, to use when making offsets into the array).
Originally Posted by koh
...
if ( strcmp( words[i],words) == 0 )
...
error message says:
error c2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char*'

..but then, i didn't use pointers
A few additional comments:

The value of count doesn't change, so it doesn't have to be in the loop--if that line assigning to z is really what you want to do.
Originally Posted by koh
...
for (int i=0; i<strlen(words); i++)
{
words[i]= tolower(words[i]);
z = count + 5;

}
...
Similar idea here. The loop will always end with i equal to count - 1, so making that last assignment to z doesn't have to be inside the loop--again, if that's what you want it to do.
Originally Posted by koh
...
for (i=0; i < count; i++)
{
if ( strcmp( words[i],words) == 0 )
z = i;
}
...
Continuing the same line of thought, z<count will always be true, so the if statement isn't necessary.
Originally Posted by koh
...
if (z<count)
{
ofstream file;
file.open("WORDS.txt", ios::app);
...

This last bit is a little strange--renaming a file that no longer exists?
Originally Posted by koh
...
system("del words.txt");
system("ren words.txt words.txt");
}
...
--sg
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC