Program has stopped working.

I made this program which it asks for the user to input a sentence, then outputs the sentence in a certain order. When I run the program,a window pops up saying that it has stopped working. Is there anything that can be removed, or a way to fix the problem. I am using C++ Eclipse v3.7.1 Hello World MinGW GCC.

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
  #include <iostream>
using namespace std;

int main() {
	int cases,case_num;
	char a1[100],b1[100],c1[100],d1[100],e1[100],f1[100],g1[100],h1[100],i1[100],j1[100];
	char k1[100],l1[100],m1[100],n1[100],o1[100],p1[100],q1[100],r1[100],s1[100],t1[100];
	char u1[100],v1[100],w1[100],x1[100],y1[100],z1[100],A1[100],B1[100],C1[100],D1[100];
	char E1[100],F1[100],G1[100],H1[100],I1[100],J1[100],K1[100],L1[100],M1[100],N1[100];
	char O1[100],P1[100],Q1[100],R1[100],S1[100],T1[100],U1[100],V1[100],W1[100],X1[100],Y1[100],Z1[100];
	cout<<"How many cases?";
	cin>>cases;//asks for how many sentences the user wants to input.
	for(case_num=0;case_num<cases;case_num++)
	{
		char word[100];
		int x;
		cout<<endl<<"A sentence:";
		cin >> word;
		for(x=0;word[x]!='\0';x++)
		{
			if(int(word[x])==65)//Takes the character and turns it into its number using ASCII.
			{
				int A;
				A1[A]='A';//if it equals the number it stores the character onto another variable.
				A++;//changes the array by one.
			}
			 if(int(word[x])==97)//the same code throughout.
			{
				int a;
				a1[a]='a';
				a++;
			}
			 if(int(word[x])==66)
			{
				int B;
				B1[B]='B';
				B++;
			}
			if(int(word[x])==98)
			{
				int b;
				b1[b]='b';
				b++;
			}
			if(int(word[x])==99)
			{
				int c;
				c1[c]='c';
				c++;
			}
			if(int(word[x])==100)
			{
				int d;
				d1[d]='d';
				d++;
			}
			if(int(word[x])==67)
			{
				int C;
				C1[C]='C';
				C++;
			}
			if((int)word[x]==68)
			{
				int D;
				D1[D]='D';
				D++;
			}
			if((int)word[x]==101)
			{
				int e;
				e1[e]='e';
				e++;
			}
			if((int)word[x]==102)
			{
				int f;
				f1[f]='f';
				f++;
			}
			if((int)word[x]==103)
			{
				int g;
				g1[g]='g';
				g++;
			}
			if((int)word[x]==104)
			{
				int h;
				h1[h]='h';
				h++;
			}
			if((int)word[x]==105)
			{
				int i;
				i1[i]='i';
				i++;
			}
			if((int)word[x]==106)
			{
				int j;
				j1[j]='j';
				j++;
			}
			if((int)word[x]==107)
			{
				int k;
				k1[k]='k';
				k++;
			}
			if((int)word[x]==108)
			{
				int l;
				l1[l]='l';
				l++;
			}
			if((int)word[x]==109)
			{
				int m;
				m1[m]='m';
				m++;
			}
			if((int)word[x]==110)
			{
				int n;
				n1[n]='n';
				n++;
			}
			if((int)word[x]==111)
			{
				int o;
				o1[o]='o';
				o++;
			}
			if((int)word[x]==112)
			{
				int p;
				p1[p]='p';
				p++;
			}
			if((int)word[x]==113)
			{
				int q;
				q1[q]='q';
				q++;
			}
			if((int)word[x]==114)
			{
				int r;
				r1[r]='r';
				r++;
			}
			if((int)word[x]==115)
			{
				int s;
				s1[s]='s';
				s++;
			}
			if((int)word[x]==116)
			{
				int t;
				t1[t]='t';
				t++;
			}
			if((int)word[x]==117)
			{
				int u;
				u1[u]='u';
				u++;
			}
			if((int)word[x]==118)
			{
				int v;
				v1[v]='v';
				v++;
			}
			if((int)word[x]==119)
			{
				int w;
				w1[w]='w';
				w++;
			}
			if((int)word[x]==120)
			{
				int x;
				x1[x]='x';
				x++;
			}
			if((int)word[x]==121)
			{
				int y;
				y1[y]='y';
				y++;
			}
			if((int)word[x]==122)
			{
				int z;
				z1[z]='z';
				z++;
			}
			if((int)word[x]==69)
			{
				int E;
				E1[E]='E';
				E++;
			}
			if((int)word[x]==70)
			{
				int F;
				F1[F]='F';
				F++;
			}
			if((int)word[x]==71)
			{
				int G;
				G1[G]='G';
				G++;
			}
			if((int)word[x]==72)
			{
				int H;
				H1[H]='H';
				H++;
			}
			if((int)word[x]==73)
			{
				int I;
				I1[I]='I';
				I++;
			}
			if((int)word[x]==74)
			{
				int J;
				J1[J]='J';
				J++;
			}
			if((int)word[x]==75)
			{
				int K;
				K1[K]='K';
				K++;
			}
			if((int)word[x]==76)
			{
				int L;
				L1[L]='L';
				L++;
			}
			if((int)word[x]==77)
			{
				int M;
				M1[M]='M';
				M++;
			}
			if((int)word[x]==78)
			{
				int N;
				N1[N]='N';
				N++;
			}
			if((int)word[x]==79)
			{
				int O;
				O1[O]='O';
				O++;
			}
			if((int)word[x]==80)
			{
				int P;
				P1[P]='P';
				P++;
			}
			if((int)word[x]==81)
			{
				int Q;
				Q1[Q]='Q';
				Q++;
			}
			if((int)word[x]==82)
			{
				int R;
				R1[R]='R';
				R++;
			}
			if((int)word[x]==83)
			{
				int S;
				S1[S]='S';
				S++;
			}
			if((int)word[x]==84)
			{
				int T;
				T1[T]='T';
				T++;
			}
			if((int)word[x]==85)
			{
				int U;
				U1[U]='U';
				U++;
			}
			if((int)word[x]==86)
			{
				int V;
				V1[V]='V';
				V++;
			}
			if((int)word[x]==87)
			{
				int W;
				W1[W]='W';
				W++;
			}
			if((int)word[x]==88)
			{
				int X;
				X1[X]='X';
				X++;
			}
			if((int)word[x]==89)
			{
				int Y;
				Y1[Y]='Y';
				Y++;
			}
			if((int)word[x]==90)
			{
				int Z;
				Z1[Z]='Z';
				Z++;
			}
			cout<<T1<<t1<<H1<<h1<<E1<<e1<<Q1<<q1<<U1<<u1<<I1<<i1<<C1<<c1<<K1<<k1<<B1<<b1;
			cout<<R1<<r1<<O1<<o1<<W1<<w1<<N1<<n1<<F1<<f1<<X1<<x1<<J1<<j1<<M1<<m1<<P1<<p1;
			cout<<S1<<s1<<V1<<v1<<L1<<l1<<A1<<a1<<Z1<<z1<<Y1<<y1<<D1<<d1<<G1<<g1;
//outputs the letters to make the pangram "The quick brown fox jumps over the lazy dog"
		}
	}
	return 0;
}
1
2
3
int A;//declaring int A but not initializing it
A1[A]='A';//accessing the array A1 with an not initialized variable -> crash
A++;


Try something like this:

int A = 0; //or any other value of your choice

Anyway, what is your code supposed to do? It doesn't make sense at all.
Last edited on
have you tried using std::string instead of char arrays? and I don't see what you are doing with all those if statements it looks to me like you are saying if 'a' == 'a' then reset 'a' to 'a'.
and anyways you could of just used a loop instead of all those if statements

@machtl

Anyway, what is your code supposed to do? It doesn't make sense at all.

I was thinking the same thing

@op you could try something like

1
2
3
std::string str = std::string();
std::getline( std::cin , str );
std::cout << str << std::endl;
Last edited on
Topic archived. No new replies allowed.