decoder

im working a decoder for my project and i need a function that includes white-space that i can originate the data(char array) into an array here is my code if any1 is curious
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
//
//  main.cpp
//  cipher
//
//  Created by Home on 3/12/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

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

class decoder{
private: 
    char notcoded[50], eord;
    ifstream message;
    
public:
    bool inputarray(){
        message.open ("/Users/home/Desktop/cipher/cipher/message.txt");
        message.exceptions(ifstream::badbit);
        try{
            for (int i = 0; i < 50; i++){
                message >> notcoded[i];
            }
        }
        catch(ifstream::failure &e){
            cout << "could not open file!";
            return false;
        }
        message.close();
        return true; 
    }
    
    void request(){
        cout << "Should this program (E)ncrypt or (D)ecrypt the message file? ";
        cin >> eord; 
    }
    
    void switchD(){
        switch (eord) {
            case 'e':
                for (int i = 0; i < 50; i++){
                    for (int j = 0; j != 3; j++){
                        if(notcoded[i] == 'x'){
                            notcoded[i] = 'a';
                        }
                        if (notcoded[i]== '\0'){
                            break; 
                        }
                        if ((notcoded[i] >= 'a') && (notcoded[i] <= 'z')){
                            break;  
                        }
                        ++notcoded[i];
                        
                    }
                }
                cout << notcoded;
                break;
            case 'd':
                for (int i = 0; i < 50; i++){
                    for (int j = 0; j != 3; j++){
                        if(notcoded[i] == 'x'){
                            notcoded[i] = 'a';
                        }
                        if (notcoded[i]== '\0'){
                         break; 
                        }
                        if ((notcoded[i] >= 'a') && (notcoded[i] <= 'z')){
                            break;  
                        }
                        --notcoded[i];
                        
                    }
                }
                cout << notcoded;
                break;
            case 'E':
                for (int i = 0; i < 50; i++){
                    for (int j = 0; j != 3; j++){
                        if(notcoded[i] == 'x'){
                            notcoded[i] = 'a';
                        }
                        if (notcoded[i]== '\0'){
                            break; 
                        }
                        if ((notcoded[i] >= 'a') && (notcoded[i] <= 'z')){
                            break;  
                        }
                        ++notcoded[i];
                        
                    }
                }
                cout << notcoded;
                break;
            case 'D':
                for (int i = 0; i < 50; i++){
                    for (int j = 0; j != 3; j++){
                        if(notcoded[i] == 'x'){
                            notcoded[i] = 'a';
                        }
                        if (notcoded[i]== '\0'){
                            break;
                        }
                        if ((notcoded[i] >= 'a') && (notcoded[i] <= 'z')){
                            break;   
                        }
                        --notcoded[i];
                        
                    }
                }
                cout << notcoded; 
                break;
            default:
                cout << "invalid entry"; 
                break;
        }

    }
    
};

int main(){
    decoder one; 
    if(one.inputarray() == true){
    one.request();
    one.switchD(); 
    }
    return 0;
}

the code i need help with is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
bool inputarray(){
        message.open ("/Users/home/Desktop/cipher/cipher/message.txt");
        message.exceptions(ifstream::badbit);
        try{
            for (int i = 0; i < 50; i++){
                message >> notcoded[i];
            }
        }
        catch(ifstream::failure &e){
            cout << "could not open file!";
            return false;
        }
        message.close();
        return true; 
    }
    

i just need a way for it to include the whitespace within the file, because currently it does not. thankyou in advance.
Try using getline.

http://www.cplusplus.com/reference/iostream/istream/getline/

(it'll look something like message.getline(notcoded, 50);)
Topic archived. No new replies allowed.