I need to create a program in which I could how many times a word appears in a string, and I included * because of strchr and my program works if I put this for example
int main(void) {
const char *needle, *stack;
needle = "a"; stack = "aaa";
printf("[%s] exists %d times in [%s]\n", needle, count(needle, stack), stack);
return 0;
}
and output would be 3, you have "a" appearing 3 times in "aaa" , but if for example I try to get stack from std input with
scanf("[%s]", &stack);
my program doesn't work, also I would like to create a 2D version of this so I need to merge chars from a 2D array into a string also, but if I put them into an array of chars, my program doesn't work also. Please don't suggest me other soutions to solve this problem because it has to be done similar to this.