I am trying to change the characters in a string using a for loop, here is my code:
#include <stdio.h>
int main(){
char h[] = "ABCDEFGH";
printf("h : %s\n", h);
int i = 0;
for(i; i<sizeof(h)-1; i++){
printf("i : %i\n", i);
printf("Starting value : %d\n", h[i]);
h[i] = "A";
printf("Test replace h[%u] : %d\n", i, h[i]);
}
printf("Final product : %s\n", h);
}
Here is my output:
h : ABCDEFGH
i : 0
Starting value : 65
Test replace h[0] : 117
i : 1
Starting value : 66
Test replace h[1] : 117
i : 2
Starting value : 67
Test replace h[2] : 117
i : 3
Starting value : 68
Test replace h[3] : 117
i : 4
Starting value : 69
Test replace h[4] : 117
i : 5
Starting value : 70
Test replace h[5] : 117
i : 6
Starting value : 71
Test replace h[6] : 117
i : 7
Starting value : 72
Test replace h[7] : 117
Final product : uuuuuuuu
Why are the values at each index integers (forcing me to use %d instead of %s)? What do those numbers represent? Why is the final product "uuuuuuuu" instead of "AAAAAAAA"? and how can I change the code to do what I am trying to do?