string prob


hi could some body help me?
im making a program that writes in a file.txt
how can i compare my "char x" to another char?

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

int main()
{

char x[100];
char y[100];





cout << "enter title" << endl;
gets(y);
ofstream rave(y, ios::out);

cout << "enter word" << endl;
do
{
gets(x);
if (x!= (?)) // <= i need something that "char x" could be compare to so that my if comd will execute
{
rave << x;
}

}while(x != (?)); // <= same above

rave.close();

}
I might be wrong but I think by using != it would have to be the exact char you specify in (?)

I am pretty new to C++ but i use != as a sentinel statement. Like if the user enters (x != -1) when the user hits -1 the program ends there.

Hope that might help a little. Or atleast maybe get you thinking of a better way to solve it :)
You can either use string x instead of char x[100] and then use == to compare it with another string, or use strcmp ( http://www.cplusplus.com/reference/clibrary/cstring/strcmp/ ).

Hope this helps
wew tnx hamsterman you fill in the part that i was missing.
Topic archived. No new replies allowed.