Help!!! It keeps saying input file did not open in my program output!

Here is the program... I need the output to decode a message but it keeps saying input file did not open when I run my program. I use MAC and Xcode to compile! Any help would be great. Thanks!

The file with the input data can be downloaded and saved on your computer. It is called encoded_quotes.txt and the code inside is below....


8aF[TVSF[UP[ESJOL[ZPVS[nWBMUJOF188zVOU[bMBSB[IB
E[GPS[ZFBST[MBCPSFE[VOEFS[UIF[EFMVTJPO[UIBU[h[XBT
[OPU[POMZQFSQFUVBMMZ[$[ZFBST[PME9[CVU[BMTP[B[HJ
SM188hNNFEJBUFMZ9[NZ[GFFU[CFHBO[UP[TXFBU[BT[UIP
TF[UXP[GMVGGZ[MJUUMF[CVOOJFTXJUI[B[CMVF[CVUUPO[
FZF[TUBSFE[TBQQJMZ[VQ[BU[NF188gF[MPPLT[MJLF[B[EFSB
OHFE[dBTUFS[aVOOZ188gn1[gn1[gn188sIF[TOBQ[PG[B[GF
X[TQBSLT9[B[RVJDL[XIJGG[PG[PAPOF9[BOE[UIF[MBNQ[CMB
AFEGPSUI[JO[VOQBSBMMFMFE[HMPSZ188nI9[MPPL[BU[U
IBU7[vJMM[ZPV[MPPL[BU[UIBU5[hTO4U[UIBU[HMPSJPVT5[h
U4T111JU4T111[JU4T[JOEFTDSJCBCMZ[CFBVUJGVM7[h
U[SFNJOET[NF[PG[UIF[ePVSUI[PG[iVMZ788qBOEZ9[IPX[EP[U
IF[MJUUMF[QJHHJFT[HP588hU[JT[B[MBNQ9[ZPV[OJODPNQ
PPQ9[CVU[JU4T[B[lBKPS[zXBSE1[h[XPO[JU788xFBI9[NJOE[QP
XFS9[rXFEF6[NJOE[QPXFS188sIF[MJOF[XBJUJOH[UP[TFF[rBO
UB[bMBVT[TUSFUDIFE[BMM[UIF[XBZ[CBDL[UP[sFSSFgBVUF1
[zOE[h[XBT[BU[UIF[FOE[PG[JU188ePPUCBMM5[ePPUCBMM5[vIB
U4T[B[GPPUCBMM5[vJUI[VODPOTDJPVT[XJMM[NZ[WPJDFTRV
FBLFE[P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VSLFZ[B[MB[jJOH7[nS[HBM
MPOT[PG[UVSLFZ[TPVQ7[fPOF9[zkk[fnmd78
[/code]



Here is the rest of the code I have so far. I'm not sure If I'm connecting it or what! Let me know what you think I should change! So lost!!!!!!!
Thanks!



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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

//checks if a character is a special character
bool isspecial(char ch)
{
    if(toascii(ch)==20 || toascii(ch)==22)
        return true;
    else
        return false;
}

//change i.e. decode a lower case character
char changeLower(char ch)
{
    char decoded_ch;
    if(ch=='z')
    {
        decoded_ch='A';
    }
    else
    {
        decoded_ch=toupper(ch)+1;
    }
    return decoded_ch;
}

//change i.e. decode a upper case character
char changeUpper(char ch)
{
    char decoded_ch;
    if(ch=='A')
    {
        decoded_ch='z';
    }
    else
    {
        decoded_ch=tolower(ch)-1;
    }
    return decoded_ch;
}

//change i.e. decode a punctuation character
char changePunct(char ch)
{
    char decoded_ch;
    switch(ch)
    {
        case ')':
            decoded_ch='0';
            break;
        case '!':
            decoded_ch='1';
            break;
        case '@':
            decoded_ch='2';
            break;
        case '#':
            decoded_ch='3';
            break;
        case '$':
            decoded_ch='4';
            break;
        case '%':
            decoded_ch='5';
            break;
        case '^':
            decoded_ch='6';
            break;
        case '&':
            decoded_ch='7';
            break;
        case '*':
            decoded_ch='8';
            break;
        case '(':
            decoded_ch='9';
            break;
        default:
            decoded_ch=ch;
            break;
    }
    return decoded_ch;
}

//change i.e. decode a digit
char changeDigit(char ch)
{
    char decoded_ch;
    switch(ch)
    {
        case '1':
            decoded_ch='-';
            break;
        case '2':
            decoded_ch='.';
            break;
        case '3':
            decoded_ch=')';
            break;
        case '4':
            decoded_ch='(';
            break;
        case '5':
            decoded_ch='\'';
            break;
        case '6':
            decoded_ch='?';
            break;
        case '7':
            decoded_ch=';';
            break;
        case '8':
            decoded_ch='!';
            break;
        case '9':
            decoded_ch='\"';
            break;
    }
    return decoded_ch;
}

//change i.e. decode a special character
char changeSpecial(char ch)
{
    char decoded_ch;
    if(toascii(ch)==20)
    {
        decoded_ch='\n';
    }
    else if(toascii(ch)==22)
    {
        decoded_ch=' ';
    }
    else
    {
        decoded_ch=ch;
    }
    return decoded_ch;
}

//main function
int main() {
    ifstream infile; //input file stream variable
    infile.open("./src/encoded_quotes.txt");
    
    if(infile.fail()) //if the input file failed to open
    {
        cout<<"input file did not open."<<endl;
        exit(-1);
    }
    
    char ch; //stores a character read from file
    infile>>ch;
    //cout<<ch;
    while(infile) //while there are charcaters in file
    {
        char decoded_ch; //decoded character
        //cascading if condition to check type of character
        if(isalpha(ch))
        {
            if(isupper(ch))
            {
                decoded_ch=changeUpper(ch);
            }
            else if(islower(ch))
            {
                decoded_ch=changeLower(ch);
            }
        }
        else if(isdigit(ch))
        {
            decoded_ch=changeDigit(ch);
        }
        else if(ispunct(ch))
        {
            decoded_ch=changePunct(ch);
        }
        else if(isspecial(ch))
        {
            cout<<"special"<<endl;
            decoded_ch=changeSpecial(ch);
        }
        cout<<decoded_ch; //displays decoded character
        infile>>ch; //reads next character
    }
    
    infile.close(); //closes file
    return 0;
}
Last edited on
That's what happens when the file is not in the folder, in this case

"./src/encoded_quotes.txt"

Edit, just to be sure tell me what you think ./src means....
Last edited on
Samuel I have no idea what src stand for....
What exactly do you mean by file isn't in folder?
Oh... Its just a variable name. I have no idea how to put the actual file there. I have MAC
Okay I got file in using:

1
2
3
4
5

int main() {
    ifstream infile; //input file stream variable
    infile.open("/Users/Tanner/Desktop/Prog6/Prog6/encoded_quotes.txt");




My output is now:

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
!Bespecial
 surespecial
 tospecial
 drinkspecial
 yourspecial
 Ovaltine-!special

special

!Auntspecial
 Claraspecial
 hadspecial
 forspecial
 yearsspecial
 laboredspecial
 underspecial
 thespecial
 delusionspecial
 thatspecial
 Ispecial
 wasspecial
 notspecial
 onlyspecial

perpetuallyspecial
 4special
 yearsspecial
 old"special
 butspecial
 alsospecial
 aspecial
 girl-!special

special

!Immediately"special
 myspecial
 feetspecial
 beganspecial
 tospecial
 sweatspecial
 asspecial
 thosespecial
 twospecial
 fluffyspecial
 littlespecial
 bunniesspecial

withspecial
 aspecial
 bluespecial
 buttonspecial
 eyespecial
 staredspecial
 sappilyspecial
 upspecial
 atspecial
 me-!special

special

!Hespecial
 looksspecial
 likespecial
 aspecial
 derangedspecial
 Easterspecial
 Bunny-!special

special

!HO-special
 HO-special
 HO-!special

special

!Thespecial
 snapspecial
 ofspecial
 aspecial
 fewspecial
 sparks"special
 aspecial
 quickspecial
 whiffspecial
 ofspecial
 ozone"special
 andspecial
 thespecial
 lampspecial
 blazedspecial

forthspecial
 inspecial
 unparalleledspecial
 glory-!special

special

!Oh"special
 lookspecial
 atspecial
 that;special
 Willspecial
 youspecial
 lookspecial
 atspecial
 that'special
 Isn(tspecial
 thatspecial
 glorious'special
 It(s---special

it(s---special
 it(sspecial
 indescribablyspecial
 beautiful;special
 Itspecial
 remindsspecial
 mespecial
 ofspecial
 thespecial
 Fourthspecial
 ofspecial
 July;!special

special

!Randy"special
 howspecial
 dospecial
 thespecial
 littlespecial
 piggiesspecial
 go'!special

special

!Itspecial
 isspecial
 aspecial
 lamp"special
 youspecial
 nincompoop"special
 butspecial
 it(sspecial
 aspecial
 Majorspecial
 Award-special
 Ispecial
 wonspecial
 it;!special

special

!Yeah"special
 mindspecial
 power"special
 Swede?special
 mindspecial
 power-!special

special

!Thespecial
 linespecial
 waitingspecial
 tospecial
 seespecial
 Santaspecial
 Clausspecial
 stretchedspecial
 allspecial
 thespecial
 wayspecial
 backspecial
 tospecial
 Terrespecial

Haute-special
 Andspecial
 Ispecial
 wasspecial
 atspecial
 thespecial
 endspecial
 ofspecial
 it-!special

special

!Football'special
 Football'special
 What(sspecial
 aspecial
 football'special
 Withspecial
 unconsciousspecial
 willspecial
 myspecial
 voicespecial

squeakedspecial
 outspecial
 (football(-!special

special

!Okay"special
 getspecial
 himspecial
 outspecial
 ofspecial
 here-!special

special

!Aspecial
 football'special
 Ohspecial
 no"special
 whatspecial
 wasspecial
 Ispecial
 doing'special
 Wakespecial
 up"special
 Stupid;special
 Wakespecial
 up;!special

special

!No;special
 No;special
 Ispecial
 wantspecial
 anspecial
 Officialspecial
 Redspecial
 Ryderspecial
 CarbineActionspecial
 TwoHundredShotspecial

Rangespecial
 Modelspecial
 Airspecial
 Rifle;!special

special

!You(llspecial
 shootspecial
 yourspecial
 eyespecial
 out"special
 kid-!special

special

!Ofspecial
 course-special
 Santa-special
 Thespecial
 bigspecial
 man-special
 Thespecial
 headspecial
 honcho-special
 Thespecial
 connection-special
 Ha"special
 myspecial

motherspecial
 hadspecial
 slippedspecial
 upspecial
 thisspecial
 time-!special

special

!Withspecial
 asspecial
 muchspecial
 dignityspecial
 asspecial
 hespecial
 couldspecial
 muster"special
 thespecial
 Oldspecial
 Manspecial
 gatheredspecial
 upspecial
 thespecial

sadspecial
 remainsspecial
 ofspecial
 hisspecial
 shatteredspecial
 majorspecial
 award-special
 Laterspecial
 thatspecial
 night"special
 alonespecial
 inspecial

thespecial
 backyard"special
 hespecial
 buriedspecial
 itspecial
 nextspecial
 tospecial
 thespecial
 garage-special
 Nowspecial
 Ispecial
 couldspecial
 neverspecial
 bespecial
 sure"special

butspecial
 Ispecial
 thoughtspecial
 thatspecial
 Ispecial
 heardspecial
 thespecial
 soundspecial
 ofspecial
 !Taps!special
 beingspecial
 played"special
 gently-!special

special

!Groverspecial
 Dill;special
 Farkus(sspecial
 crummyspecial
 littlespecial
 toadie-special
 Mean;special
 Rotten;special
 Hisspecial
 lipsspecial

curledspecial
 overspecial
 hisspecial
 greenspecial
 teeth-!special

special

!Don(tspecial
 youspecial
 touchspecial
 that;special
 Youspecial
 werespecial
 alwaysspecial
 jealousspecial
 ofspecial
 thisspecial
 lamp-!special

special

!Whatspecial
 isspecial
 thespecial
 namespecial
 ofspecial
 thespecial
 Lonespecial
 Ranger(sspecial
 nephew(sspecial
 horse'!special

special

!A
 Victor;special
 Hisspecial
 namespecial
 isspecial
 Victor-!special

special

!Thespecial
 heavenlyspecial
 aromaspecial
 stillspecial
 hungspecial
 inspecial
 thespecial
 house-special
 Butspecial
 itspecial
 wasspecial
 gone"special
 allspecial
 gone;special

Nospecial
 turkey;special
 Nospecial
 turkeyspecial
 sandwiches;special
 Nospecial
 turkeyspecial
 salad;special
 Nospecial
 turkeyspecial
 gravy;special

Turkeyspecial
 Hash;special
 Turkeyspecial
 aspecial
 laspecial
 King;special
 Orspecial
 gallonsspecial
 ofspecial
 turkeyspecial
 soup;special
 Gone"special
 ALLspecial
 GONE;!Program ended with exit code: 0



I'm not sure if this is right??? Help?!
I know what I need to change!!

Okay I need to get special out after every word and it will be perfect.

How would I go about that?
Topic archived. No new replies allowed.