Okay, I have to do some mini-review for my programming class, but I haven't touched C++ in ~6months or so, so I'm a bit rusty.
I have to have the user input text, then reject it if it contains profanity.
this is what I have so far, but I can't seem to get it to work. As you can see, I have the words it's checking for in a seperate file so it's easy to update.
Code:
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
char str[100];
string prof1, prof2, prof3, prof4, prof5;
int main()
{
ifstream fin;
fin.open("profanity.txt");
char *pdest;
int result;
fin >> prof1 >> prof2 >> prof3 >> prof4 >> prof5;
string words[5] = {prof1, prof2, prof3, prof4, prof5};
cout << "Enter text: ";
cin >> str;
for(int a=1; a<5; a++)
{
pdest = strstr( str, words[a] );
if ( pdest != NULL )
{
cout << "Profanity found!";
return 0;
}
else
cout << "No profanity found\n";
}
return 0;
}
any help would be appreciated. I can't figure this out, it should be pretty easy, and it's driving me nuts!