Question: I have been trying to shuffle this array from characters 3 3 - 1 2 6 , and when i do it , the final

I have been trying to shuffle this array from characters 33-126, and when i do it, the final result adds an extra 0 to it, and i dont know why, it is shufflling all the values i want plus a null or 0 character void generatingMixedSoup(char soup[]){
srand(time(NULL));
const int numValidChars =126-33;
char validChars[numValidChars];
for (int i =0; i < numValidChars -1; i++){
validChars[i]= i +33;
printf("validChars[%d]=%c ASCII CODE: %d
", i, validChars[i], validChars[i]);
//printf("%c", validChars[i]);
}
printf("
");
//validChars[numValidChars -1]='\0';
for (int i =0; i < numValidChars; i++){
int swapIndex = rand()%(numValidChars);
char temp = validChars[i];
if (validChars[i]!=0){
validChars[i]= validChars[swapIndex];
validChars[swapIndex]= temp;
}
}
for (int i =0; i < numValidChars; i++){
printf("validChars[%d]=%c ASCII CODE: %d
", i, validChars[i], validChars[i]);
}
//char soup[11];
/*
for (int i =0; i <10; i++){
if (validChars[i]=!'\0'){
soup[i]= validChars[i];
}
printf("soup[%d]=%c
", i, soup[i]);
}
//soup[11]='\0';
//printf("Soup: %s
", soup);*/
}
/*
void createSoup( char soup[]){
printf("Soup: %
", soup);
printf("Soup code: ");
for (int i =0; soup[i]!='\0'; i++){
printf("%d", soup[i]);
}
printf("
");
}
*/
int main(){
char soup[10];
generatingMixedSoup(soup);
//createSoup(soup);
} this is the code i dont know what im doing wrong i am frustrated.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!