-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruiz.cpp
87 lines (81 loc) · 1.68 KB
/
ruiz.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
Created by: Christopher Ruiz-Rodriguez
File: ruiz.cpp
Purpose: Driver for programming assignment 1
*/
#include <iostream>
#include <string.h>
#include <vector>
#include <fstream>
#include "llist.h"
using namespace std;
int main()
{
char x;
int state = 0;
string s,s1,s2; //Strings will be used to record which messages are spam
vector <string> v; //This vector will hold all strings
bool flag = false;
//Initialize linked list
llist L1;
L1.createList();
//L1.displayAll();
//Begin reading
fstream fin;
fin.open("messagefile.txt");
x = fin.get();
while(x != EOF)
{
if(state == 17)
{
//cout<<"We made it here!"<<endl;
s = "";
while(x >= 48 && x <= 57)
{
s+=x;
x = fin.get();
}
//cout<<s<<endl;
}
state = L1.manState(state, x);
if(x == '\n')
cout<<"Input:New line\tState: "<<state<<endl;
else
cout<<"Input: "<<x<<"\tState: "<<state<<endl;
if(state == 83 || state == 74)
flag = true;
//RestFA & message
if(state == 89 && flag == true)
{
s1 = "Message #";
s2 = " is spam.";
s1 += s;
s1 += s2;
v.push_back(s1);
state = 0;
flag = false;
//cout<<"Flag was set to true"<<endl;
}
else if(state == 89)
{
state = 0;
flag = false;
//cout<<"Flag was set to false"<<endl;
}
x = fin.get();
}
fin.close();
//Keep track & print all messages that are spam
if(v.size() != 0)
{
cout<<"\nSpam Messages"<<endl;
cout<<"-----------------------------------------------"<<endl;
for(int i = 0;i < v.size();i++)
{
cout<<v[i]<<endl;
}
}
else
cout<<"There are no spam messages."<<endl;
return 0;
}