C++ Random ID, and random Answers
Im making a program that outputs an ID, and the random guesses of the answers.
You can guess A, B, C, D, and the ID has random characters in the first 2 letters, and numbers in the next 3.
The error is that the program gives me an ID like this: YN420BBBBCBACDBBCDB
You can see the ID clearly in it. But, it puts the random answer with it, and its in one variable. Here's my code:
#include <iostream>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <string>
#include <fstream>
using namespace std;
char id[6];
char answers[16];
int main()
{
srand(time(NULL));
int random =rand() % 500+1;
const char* const a_to_d = "ABCD" ;
const char* const a_to_z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
const char* const zero_to_seven = "01234567";
for (int i = 0; i < random; ++i){
int ri = rand() % 26;
id[0] = a_to_z[ri];
int ri1 = rand() % 26;
id[1] = a_to_z[ri1];
int ri2 = rand() % 7;
id[2] = zero_to_seven[ri2];
int ri3 = rand() % 7;
id[3] = zero_to_seven[ri3];
int ri4 = rand() % 7;
id[4] = zero_to_seven[ri4];
id[6] = 0;
cout<<id<<" "<<answers<<endl<<endl;
int fi = rand() % 4;
answers[0] = a_to_d[fi];
int fi1 = rand() % 4;
answers[1] = a_to_d[fi1];
int fi2 = rand() % 4;
answers[2] = a_to_d[fi2];
int fi3 = rand() % 4;
answers[3] = a_to_d[fi3];
int fi4 = rand() % 4;
answers[4] = a_to_d[fi4];
int fi5 = rand() % 4;
answers[5] = a_to_d[fi5];
int fi6 = rand() % 4;
answers[6] = a_to_d[fi6];
int fi7 = rand() % 4;
answers[7] = a_to_d[fi7];
int fi8 = rand() % 4;
answers[8] = a_to_d[fi8];
int fi9 = rand() % 4;
answers[9] = a_to_d[fi9];
int fi10 = rand() % 4;
answers[10] = a_to_d[fi10];
int fi11 = rand() % 4;
answers[11] = a_to_d[fi11];
int fi12 = rand() % 4;
answers[12] = a_to_d[fi12];
int fi13 = rand() % 4;
answers[13] = a_to_d[fi13];
int fi14 = rand() % 4;
answers[14] = a_to_d[fi14];
answers[16] = 0;
}
return 0;
}
c++ char
|
show 2 more comments
Im making a program that outputs an ID, and the random guesses of the answers.
You can guess A, B, C, D, and the ID has random characters in the first 2 letters, and numbers in the next 3.
The error is that the program gives me an ID like this: YN420BBBBCBACDBBCDB
You can see the ID clearly in it. But, it puts the random answer with it, and its in one variable. Here's my code:
#include <iostream>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <string>
#include <fstream>
using namespace std;
char id[6];
char answers[16];
int main()
{
srand(time(NULL));
int random =rand() % 500+1;
const char* const a_to_d = "ABCD" ;
const char* const a_to_z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
const char* const zero_to_seven = "01234567";
for (int i = 0; i < random; ++i){
int ri = rand() % 26;
id[0] = a_to_z[ri];
int ri1 = rand() % 26;
id[1] = a_to_z[ri1];
int ri2 = rand() % 7;
id[2] = zero_to_seven[ri2];
int ri3 = rand() % 7;
id[3] = zero_to_seven[ri3];
int ri4 = rand() % 7;
id[4] = zero_to_seven[ri4];
id[6] = 0;
cout<<id<<" "<<answers<<endl<<endl;
int fi = rand() % 4;
answers[0] = a_to_d[fi];
int fi1 = rand() % 4;
answers[1] = a_to_d[fi1];
int fi2 = rand() % 4;
answers[2] = a_to_d[fi2];
int fi3 = rand() % 4;
answers[3] = a_to_d[fi3];
int fi4 = rand() % 4;
answers[4] = a_to_d[fi4];
int fi5 = rand() % 4;
answers[5] = a_to_d[fi5];
int fi6 = rand() % 4;
answers[6] = a_to_d[fi6];
int fi7 = rand() % 4;
answers[7] = a_to_d[fi7];
int fi8 = rand() % 4;
answers[8] = a_to_d[fi8];
int fi9 = rand() % 4;
answers[9] = a_to_d[fi9];
int fi10 = rand() % 4;
answers[10] = a_to_d[fi10];
int fi11 = rand() % 4;
answers[11] = a_to_d[fi11];
int fi12 = rand() % 4;
answers[12] = a_to_d[fi12];
int fi13 = rand() % 4;
answers[13] = a_to_d[fi13];
int fi14 = rand() % 4;
answers[14] = a_to_d[fi14];
answers[16] = 0;
}
return 0;
}
c++ char
1
random.cpp: In function ‘int main()’: random.cpp:33:9: warning: array subscript 4 is above array bounds of ‘char [4]’ [-Warray-bounds] id[4] = zero_to_seven[ri4]; ~~~~^ random.cpp:65:15: warning: array subscript 14 is above array bounds of ‘char [14]’ [-Warray-bounds] answers[14] = a_to_d[fi14]; ~~~~~~~~~~^
– Ted Lyngmo
Nov 22 '18 at 19:28
You need to enable more warnings when compiling.
– Ted Lyngmo
Nov 22 '18 at 19:29
It compiles for me tho.
– Gabor2305
Nov 22 '18 at 19:29
Me too, but it gives me the warnings (which are really bad) and also runtime errors.random.cpp:33:9: runtime error: index 4 out of bounds for type 'char [4]' random.cpp:33:11: runtime error: store to address 0x00000060596a with insufficient space for an object of type 'char' 0x00000060596a: note: pointer points here 44 4a 30 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...
– Ted Lyngmo
Nov 22 '18 at 19:31
Never really saw anything like this before, im kinda new. Can you explain that one for me, please?
– Gabor2305
Nov 22 '18 at 19:32
|
show 2 more comments
Im making a program that outputs an ID, and the random guesses of the answers.
You can guess A, B, C, D, and the ID has random characters in the first 2 letters, and numbers in the next 3.
The error is that the program gives me an ID like this: YN420BBBBCBACDBBCDB
You can see the ID clearly in it. But, it puts the random answer with it, and its in one variable. Here's my code:
#include <iostream>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <string>
#include <fstream>
using namespace std;
char id[6];
char answers[16];
int main()
{
srand(time(NULL));
int random =rand() % 500+1;
const char* const a_to_d = "ABCD" ;
const char* const a_to_z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
const char* const zero_to_seven = "01234567";
for (int i = 0; i < random; ++i){
int ri = rand() % 26;
id[0] = a_to_z[ri];
int ri1 = rand() % 26;
id[1] = a_to_z[ri1];
int ri2 = rand() % 7;
id[2] = zero_to_seven[ri2];
int ri3 = rand() % 7;
id[3] = zero_to_seven[ri3];
int ri4 = rand() % 7;
id[4] = zero_to_seven[ri4];
id[6] = 0;
cout<<id<<" "<<answers<<endl<<endl;
int fi = rand() % 4;
answers[0] = a_to_d[fi];
int fi1 = rand() % 4;
answers[1] = a_to_d[fi1];
int fi2 = rand() % 4;
answers[2] = a_to_d[fi2];
int fi3 = rand() % 4;
answers[3] = a_to_d[fi3];
int fi4 = rand() % 4;
answers[4] = a_to_d[fi4];
int fi5 = rand() % 4;
answers[5] = a_to_d[fi5];
int fi6 = rand() % 4;
answers[6] = a_to_d[fi6];
int fi7 = rand() % 4;
answers[7] = a_to_d[fi7];
int fi8 = rand() % 4;
answers[8] = a_to_d[fi8];
int fi9 = rand() % 4;
answers[9] = a_to_d[fi9];
int fi10 = rand() % 4;
answers[10] = a_to_d[fi10];
int fi11 = rand() % 4;
answers[11] = a_to_d[fi11];
int fi12 = rand() % 4;
answers[12] = a_to_d[fi12];
int fi13 = rand() % 4;
answers[13] = a_to_d[fi13];
int fi14 = rand() % 4;
answers[14] = a_to_d[fi14];
answers[16] = 0;
}
return 0;
}
c++ char
Im making a program that outputs an ID, and the random guesses of the answers.
You can guess A, B, C, D, and the ID has random characters in the first 2 letters, and numbers in the next 3.
The error is that the program gives me an ID like this: YN420BBBBCBACDBBCDB
You can see the ID clearly in it. But, it puts the random answer with it, and its in one variable. Here's my code:
#include <iostream>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <string>
#include <fstream>
using namespace std;
char id[6];
char answers[16];
int main()
{
srand(time(NULL));
int random =rand() % 500+1;
const char* const a_to_d = "ABCD" ;
const char* const a_to_z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
const char* const zero_to_seven = "01234567";
for (int i = 0; i < random; ++i){
int ri = rand() % 26;
id[0] = a_to_z[ri];
int ri1 = rand() % 26;
id[1] = a_to_z[ri1];
int ri2 = rand() % 7;
id[2] = zero_to_seven[ri2];
int ri3 = rand() % 7;
id[3] = zero_to_seven[ri3];
int ri4 = rand() % 7;
id[4] = zero_to_seven[ri4];
id[6] = 0;
cout<<id<<" "<<answers<<endl<<endl;
int fi = rand() % 4;
answers[0] = a_to_d[fi];
int fi1 = rand() % 4;
answers[1] = a_to_d[fi1];
int fi2 = rand() % 4;
answers[2] = a_to_d[fi2];
int fi3 = rand() % 4;
answers[3] = a_to_d[fi3];
int fi4 = rand() % 4;
answers[4] = a_to_d[fi4];
int fi5 = rand() % 4;
answers[5] = a_to_d[fi5];
int fi6 = rand() % 4;
answers[6] = a_to_d[fi6];
int fi7 = rand() % 4;
answers[7] = a_to_d[fi7];
int fi8 = rand() % 4;
answers[8] = a_to_d[fi8];
int fi9 = rand() % 4;
answers[9] = a_to_d[fi9];
int fi10 = rand() % 4;
answers[10] = a_to_d[fi10];
int fi11 = rand() % 4;
answers[11] = a_to_d[fi11];
int fi12 = rand() % 4;
answers[12] = a_to_d[fi12];
int fi13 = rand() % 4;
answers[13] = a_to_d[fi13];
int fi14 = rand() % 4;
answers[14] = a_to_d[fi14];
answers[16] = 0;
}
return 0;
}
c++ char
c++ char
edited Nov 22 '18 at 19:49
Gabor2305
asked Nov 22 '18 at 19:25
Gabor2305Gabor2305
84
84
1
random.cpp: In function ‘int main()’: random.cpp:33:9: warning: array subscript 4 is above array bounds of ‘char [4]’ [-Warray-bounds] id[4] = zero_to_seven[ri4]; ~~~~^ random.cpp:65:15: warning: array subscript 14 is above array bounds of ‘char [14]’ [-Warray-bounds] answers[14] = a_to_d[fi14]; ~~~~~~~~~~^
– Ted Lyngmo
Nov 22 '18 at 19:28
You need to enable more warnings when compiling.
– Ted Lyngmo
Nov 22 '18 at 19:29
It compiles for me tho.
– Gabor2305
Nov 22 '18 at 19:29
Me too, but it gives me the warnings (which are really bad) and also runtime errors.random.cpp:33:9: runtime error: index 4 out of bounds for type 'char [4]' random.cpp:33:11: runtime error: store to address 0x00000060596a with insufficient space for an object of type 'char' 0x00000060596a: note: pointer points here 44 4a 30 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...
– Ted Lyngmo
Nov 22 '18 at 19:31
Never really saw anything like this before, im kinda new. Can you explain that one for me, please?
– Gabor2305
Nov 22 '18 at 19:32
|
show 2 more comments
1
random.cpp: In function ‘int main()’: random.cpp:33:9: warning: array subscript 4 is above array bounds of ‘char [4]’ [-Warray-bounds] id[4] = zero_to_seven[ri4]; ~~~~^ random.cpp:65:15: warning: array subscript 14 is above array bounds of ‘char [14]’ [-Warray-bounds] answers[14] = a_to_d[fi14]; ~~~~~~~~~~^
– Ted Lyngmo
Nov 22 '18 at 19:28
You need to enable more warnings when compiling.
– Ted Lyngmo
Nov 22 '18 at 19:29
It compiles for me tho.
– Gabor2305
Nov 22 '18 at 19:29
Me too, but it gives me the warnings (which are really bad) and also runtime errors.random.cpp:33:9: runtime error: index 4 out of bounds for type 'char [4]' random.cpp:33:11: runtime error: store to address 0x00000060596a with insufficient space for an object of type 'char' 0x00000060596a: note: pointer points here 44 4a 30 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...
– Ted Lyngmo
Nov 22 '18 at 19:31
Never really saw anything like this before, im kinda new. Can you explain that one for me, please?
– Gabor2305
Nov 22 '18 at 19:32
1
1
random.cpp: In function ‘int main()’: random.cpp:33:9: warning: array subscript 4 is above array bounds of ‘char [4]’ [-Warray-bounds] id[4] = zero_to_seven[ri4]; ~~~~^ random.cpp:65:15: warning: array subscript 14 is above array bounds of ‘char [14]’ [-Warray-bounds] answers[14] = a_to_d[fi14]; ~~~~~~~~~~^
– Ted Lyngmo
Nov 22 '18 at 19:28
random.cpp: In function ‘int main()’: random.cpp:33:9: warning: array subscript 4 is above array bounds of ‘char [4]’ [-Warray-bounds] id[4] = zero_to_seven[ri4]; ~~~~^ random.cpp:65:15: warning: array subscript 14 is above array bounds of ‘char [14]’ [-Warray-bounds] answers[14] = a_to_d[fi14]; ~~~~~~~~~~^
– Ted Lyngmo
Nov 22 '18 at 19:28
You need to enable more warnings when compiling.
– Ted Lyngmo
Nov 22 '18 at 19:29
You need to enable more warnings when compiling.
– Ted Lyngmo
Nov 22 '18 at 19:29
It compiles for me tho.
– Gabor2305
Nov 22 '18 at 19:29
It compiles for me tho.
– Gabor2305
Nov 22 '18 at 19:29
Me too, but it gives me the warnings (which are really bad) and also runtime errors.
random.cpp:33:9: runtime error: index 4 out of bounds for type 'char [4]' random.cpp:33:11: runtime error: store to address 0x00000060596a with insufficient space for an object of type 'char' 0x00000060596a: note: pointer points here 44 4a 30 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...– Ted Lyngmo
Nov 22 '18 at 19:31
Me too, but it gives me the warnings (which are really bad) and also runtime errors.
random.cpp:33:9: runtime error: index 4 out of bounds for type 'char [4]' random.cpp:33:11: runtime error: store to address 0x00000060596a with insufficient space for an object of type 'char' 0x00000060596a: note: pointer points here 44 4a 30 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...– Ted Lyngmo
Nov 22 '18 at 19:31
Never really saw anything like this before, im kinda new. Can you explain that one for me, please?
– Gabor2305
Nov 22 '18 at 19:32
Never really saw anything like this before, im kinda new. Can you explain that one for me, please?
– Gabor2305
Nov 22 '18 at 19:32
|
show 2 more comments
1 Answer
1
active
oldest
votes
Your char array needs to be null-terminated. Since its not, cout continues into the next array, until finally it finds a null-terminator. To fix this, simply increase the length by one char id[5]
and set the last value to 0 id[4] = 0
Also, your modulus operators will never cover the last value for ri and ri2. rand() % 25
the largest value you can get is 24. You actually want rand() % 26
.
It worked, thank you! :)
– Gabor2305
Nov 22 '18 at 19:36
But you haveid[4] = zero_to_seven[ri4];
andanswers[14] = a_to_d[fi14];
. I think you need to make themchar id[6]
andchar answer[16]
. and set id[5] and answer[15] to ''.
– Ted Lyngmo
Nov 22 '18 at 19:39
Thanks, Ted! ^^
– Gabor2305
Nov 22 '18 at 19:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437058%2fc-random-id-and-random-answers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your char array needs to be null-terminated. Since its not, cout continues into the next array, until finally it finds a null-terminator. To fix this, simply increase the length by one char id[5]
and set the last value to 0 id[4] = 0
Also, your modulus operators will never cover the last value for ri and ri2. rand() % 25
the largest value you can get is 24. You actually want rand() % 26
.
It worked, thank you! :)
– Gabor2305
Nov 22 '18 at 19:36
But you haveid[4] = zero_to_seven[ri4];
andanswers[14] = a_to_d[fi14];
. I think you need to make themchar id[6]
andchar answer[16]
. and set id[5] and answer[15] to ''.
– Ted Lyngmo
Nov 22 '18 at 19:39
Thanks, Ted! ^^
– Gabor2305
Nov 22 '18 at 19:46
add a comment |
Your char array needs to be null-terminated. Since its not, cout continues into the next array, until finally it finds a null-terminator. To fix this, simply increase the length by one char id[5]
and set the last value to 0 id[4] = 0
Also, your modulus operators will never cover the last value for ri and ri2. rand() % 25
the largest value you can get is 24. You actually want rand() % 26
.
It worked, thank you! :)
– Gabor2305
Nov 22 '18 at 19:36
But you haveid[4] = zero_to_seven[ri4];
andanswers[14] = a_to_d[fi14];
. I think you need to make themchar id[6]
andchar answer[16]
. and set id[5] and answer[15] to ''.
– Ted Lyngmo
Nov 22 '18 at 19:39
Thanks, Ted! ^^
– Gabor2305
Nov 22 '18 at 19:46
add a comment |
Your char array needs to be null-terminated. Since its not, cout continues into the next array, until finally it finds a null-terminator. To fix this, simply increase the length by one char id[5]
and set the last value to 0 id[4] = 0
Also, your modulus operators will never cover the last value for ri and ri2. rand() % 25
the largest value you can get is 24. You actually want rand() % 26
.
Your char array needs to be null-terminated. Since its not, cout continues into the next array, until finally it finds a null-terminator. To fix this, simply increase the length by one char id[5]
and set the last value to 0 id[4] = 0
Also, your modulus operators will never cover the last value for ri and ri2. rand() % 25
the largest value you can get is 24. You actually want rand() % 26
.
answered Nov 22 '18 at 19:32
ChrisMMChrisMM
388
388
It worked, thank you! :)
– Gabor2305
Nov 22 '18 at 19:36
But you haveid[4] = zero_to_seven[ri4];
andanswers[14] = a_to_d[fi14];
. I think you need to make themchar id[6]
andchar answer[16]
. and set id[5] and answer[15] to ''.
– Ted Lyngmo
Nov 22 '18 at 19:39
Thanks, Ted! ^^
– Gabor2305
Nov 22 '18 at 19:46
add a comment |
It worked, thank you! :)
– Gabor2305
Nov 22 '18 at 19:36
But you haveid[4] = zero_to_seven[ri4];
andanswers[14] = a_to_d[fi14];
. I think you need to make themchar id[6]
andchar answer[16]
. and set id[5] and answer[15] to ''.
– Ted Lyngmo
Nov 22 '18 at 19:39
Thanks, Ted! ^^
– Gabor2305
Nov 22 '18 at 19:46
It worked, thank you! :)
– Gabor2305
Nov 22 '18 at 19:36
It worked, thank you! :)
– Gabor2305
Nov 22 '18 at 19:36
But you have
id[4] = zero_to_seven[ri4];
and answers[14] = a_to_d[fi14];
. I think you need to make them char id[6]
and char answer[16]
. and set id[5] and answer[15] to ''.– Ted Lyngmo
Nov 22 '18 at 19:39
But you have
id[4] = zero_to_seven[ri4];
and answers[14] = a_to_d[fi14];
. I think you need to make them char id[6]
and char answer[16]
. and set id[5] and answer[15] to ''.– Ted Lyngmo
Nov 22 '18 at 19:39
Thanks, Ted! ^^
– Gabor2305
Nov 22 '18 at 19:46
Thanks, Ted! ^^
– Gabor2305
Nov 22 '18 at 19:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437058%2fc-random-id-and-random-answers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
random.cpp: In function ‘int main()’: random.cpp:33:9: warning: array subscript 4 is above array bounds of ‘char [4]’ [-Warray-bounds] id[4] = zero_to_seven[ri4]; ~~~~^ random.cpp:65:15: warning: array subscript 14 is above array bounds of ‘char [14]’ [-Warray-bounds] answers[14] = a_to_d[fi14]; ~~~~~~~~~~^
– Ted Lyngmo
Nov 22 '18 at 19:28
You need to enable more warnings when compiling.
– Ted Lyngmo
Nov 22 '18 at 19:29
It compiles for me tho.
– Gabor2305
Nov 22 '18 at 19:29
Me too, but it gives me the warnings (which are really bad) and also runtime errors.
random.cpp:33:9: runtime error: index 4 out of bounds for type 'char [4]' random.cpp:33:11: runtime error: store to address 0x00000060596a with insufficient space for an object of type 'char' 0x00000060596a: note: pointer points here 44 4a 30 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...– Ted Lyngmo
Nov 22 '18 at 19:31
Never really saw anything like this before, im kinda new. Can you explain that one for me, please?
– Gabor2305
Nov 22 '18 at 19:32