954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Delete words error!!

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

koh
Junior Poster in Training
73 posts since Jul 2004
Reputation Points: 11
Solved Threads: 0
 

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.

FireNet
Posting Whiz in Training
258 posts since May 2004
Reputation Points: 108
Solved Threads: 7
 

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

DoubleShot
Newbie Poster
10 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

Did you include string.h?

iamboredguy
Newbie Poster
23 posts since Aug 2004
Reputation Points: 12
Solved Threads: 0
 

No wait. You are trying to compare individual letters with strings when you use
words[i]. strcmp() can only accept string arguments.

iamboredguy
Newbie Poster
23 posts since Aug 2004
Reputation Points: 12
Solved Threads: 0
 

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

koh
Junior Poster in Training
73 posts since Jul 2004
Reputation Points: 11
Solved Threads: 0
 

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).
...
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 ofcount 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.
...
for (int i=0; i

Similar idea here. The loop will always end withi 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.
...
for (i=0; i < count; i++)
{
if ( strcmp( words[i],words) == 0 )
z = i;
}
...

Continuing the same line of thought,z...
if (z


This last bit is a little strange--renaming a file that no longer exists?...
system("del words.txt");
system("ren words.txt words.txt");
}
...

--sg

gusano79
Posting Pro
519 posts since May 2004
Reputation Points: 182
Solved Threads: 77
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You