I can't believe I'm starting a thread about this, but how are you suppose to add a char to a string. I've been using the following method for as long as I can remember.
gcc -Wall gives a warning of “warning: array subscript has type ‘char’”. Even though ch is a f-ing char.
Anyway, my code is not suppose to have any warnings in it at all. What is the proper way of adding a char into a char array if not this way?
Code:
... char ch = 'a'; char *str; str = (char*)malloc(x); //x is some integer str[y] = ch; //y is some integer < x free(str); ...
Anyway, my code is not suppose to have any warnings in it at all. What is the proper way of adding a char into a char array if not this way?
Comment