我试图弄清楚如何使用下面程序中的指针将字母“j”更改为“Y”:
#include <stdio.h>
#include <string.h>
int main()
{
char *buffer[] = {"ABCDEFGH", "ijklmnop", "QRSTUVWX"};
printf("the value as %%s of buffer[0] is %s\n", buffer[0]);
printf("the value as %%s of buffer[1] is %s\n", buffer[1]);
printf("the value as %%s of buffer[2] is %s\n", buffer[2]);
printf("the sizeof(buffer[2]) is %d\n", sizeof(buffer[2]));
printf("the value as %%c of buffer[1][3] is %c\n", buffer[1][3]);
printf("the value as %%c of buffer[2][3] is %c\n", buffer[2][3]);
/*create a pointer to the pointer at buffer[1]*/
char *second = buffer[1];
/*change character at position 2 of bufffer[1] to a Y*/
second++;
second = "Y";
printf("character at location in second is %c\n", *second);
printf("character at location in second+2 is %c\n", second+2);
printf("the values as %%c of second second+1 second+2 second+3 are %c %c %c %c\n",*(second),*(second+1),*(second+2),*(second+3));
return(0);
}
如何更改位于字符串数组中的字符?