I have written the following program:
char name[100], firstDigits[13], cards[5000][16];
srand(1019336);
int i, j;
char c = '0';
for(i=0;i<13;i++){
c = '0' + (rand() % 43);
while(c > 57 && c < 65){
c = '0' + (rand() % 43);
}
firstDigits[i] = c;
}
printf("%s \n", firstDigits);
for(i=0;i<5;i++){
for(j=0;j<13;j++){
cards[i][j] = firstDigits[j];
}
}
for(i=0;i<5;i++){
for(j=13;j<16;j++){
c = '0' + (rand() % 43);
while(c > 57 && c < 65){
c = '0' + (rand() % 43);
}
cards[i][j] = c;
}
}
printf("%s \n", cards[1]);
The first loop generates a string of 13 characters which are from 0-9 and A-Z. Then I want to generate an array of 5000 strings where each string's first 13 'letters' are that of firstDigits[13]. The problem is that when I try to print one of those strings like above I get as output all of the strings in the array! Why is this happening?