这里是新手。 我试图替换 char * 中的一个字符,但我的程序出错
#include <stdio.h>
int main(int argc, char **argv)
{
char *mystring ="love is alweys better yoe";
int count = 1;
for (count ; count < 23; count++)
{
if ((mystring[count] == 0x65 )) //&& ((mystring[count+1] > 0x41) && (mystring[count+1] < 0x7A)))
{
mystring[count] = 0x45; //here occur the freezing
printf ("%c\n", mystring[count]);
//break;
};
};
printf("%s\n",mystring);
return 0;
}
最佳答案
char *mystring ="love is alweys better yoe"
将 mystring 设为只读
你需要先将字符串复制到缓冲区中才能更改它
例如
char mystring[128];
strcpy( mystring , "love is alweys better yoe" );
关于c - 如何替换char *中的char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4331439/