I want to assign sinh which is saved in char* container; to tokens[0] and after assigning I want to empty the container.
For that I made void makeBlank(char* box); function.
In the main() function, I successfully assign tokens[0] = container;.
When I call makeBlank() function the container gets emptied successfully but why does tokens[0] gets emptied too???
Its says
Bus Error: 10 when I try to print tokens[0] after calling makeBlank().
Please help me with this.
Here is my code...
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void makeBlank(char* box){
int i = strlen(box);
while(box[0] != '\0'){
box[i] = '\0';
i--;
}
}
int main(){
char* container = "sinh";
char* tokens[10];
tokens[0] = container;
printf("%s is in container\n", container); // prints sinh í in container
printf("%s is in tokens\n", tokens[0]); // prints sinh í in tokens
makeBlank(container); // Creates Bus Error: 10
// printf("%s is in tokens\n", tokens[0]);
return 0;
}