String comparison code crashes

Hi, I'm writing a program that basically reads in a text and scans it for various occurances of some predifined strings and then if there is a match, I write into another text file. So far, I used a string array to store my predefined strings to be used for comparison, however, my comparison algorithm doesnt seem to work. Can someone check it out to see what might be wrong? Any input is greatly appreciated on that part or any part of the whole code too. Thanks.
Code is below
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    char wait;
    ifstream  in_stream;
    ofstream out_stream;
    size_t found1, found2, found3, found4, found5;
    string userfile, string1, string2, string3;
    string check[];
    
    cout <<  "Please provide a name for the text that\n" <<
            "you want to be checked for holidays. Add a \".txt\" at the\n" <<
            "end of your filename.\n" << endl;
            
    cin >> userfile;
    in_stream.open((userfile).c_str());
    if (in_stream.fail())
        {
           exit(1);
        }	
    else
        {
               out_stream.open("DayList.txt");
                         if (out_stream.fail())
                            {
                                   exit(1);
                            }
                         else {
                                while (!in_stream.eof())
                               {     
                                     string1 = string2;
                                     string2 = string3;
                                     in_stream >> string3;
                                     
                                     found1 = string1.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); 
                                     found2 = string2.find_first_of( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
                                     found3 = string1.find_first_of( "0123456789" );
                                     found4 = string2.find_first_of( "0123456789" );
                                     found5 = string3.find_first_of( "0123456789" 
                                     for (int m = 0; m<5; m++)
                                     {
                                        if (string3.compare(check[m]) == 0)
                                        out_stream << string3 << "\n" ;
                                     } 
                               
                               }
                               in_stream.close();
                               out_stream.close();
                              }
                            }
   system ("Pause");
   return 0;
   
}

Ps. I added some couts to check for errors.
Last edited on
Please edit your post and put the source inside code tags. It will make your post a lot more legible and folks here will be more likely to look at it.
Thanks for the input, PanGalactic. I edited the code. Any other input is appreciated.
Line 68: m<6 should be m<5.
Hey, thanks PanGalactic. That fixed it. I'm also trying to check if the first character in every string is a Capital letter or an integer. I used the .find_first_of() operator. Is the syntax correct or is there an easier way to do that?
Topic archived. No new replies allowed.