I'm trying to terminate a string early based on some arbitrary condition, by doing this:
void end_string_early(char string[], int len) {
int i;
char j;
for (i=0;i<len;i++) {
j = string[i];
if (arbitrary_condition(j)) {
string[i] = "a";
}
}
}
I get the compile error:
warning: assignment makes integer from pointer without a cast
What confuses me, is if I do the exact same thing with an int array (changing the value to be another int, instead of a) then it works perfectly. Perhaps it's something with how the argument is being passed? (Though I was under the impression all arrays were passed by ref) I'm not entirely sure and this is my first go at C (working through K&R book).
"a"is an array (of length 2) which decays to a pointer before the assignment. You want'a'(anintthat can be interpreted as achar).