#include
#include
#include
#include
#include
#include
#include
#include
static char pstring[] = "Hello\n"; // 这里不能是char*
int main()
{
char tmp ;
char* pstr = strchr(pstring,‘l‘);
printf("pstr is %s %p\n",pstr,pstr);
#if 0
// 搜后面的
pstr = strchr(pstr+1,‘l‘); // 是strchr不是strstr
printf("next pastr is %s\n",pstr);
#endif //
//需要He
tmp = *pstr;
printf("%c",tmp);
pstr[0] = ‘\0‘;
printf("length is %d\n",strlen(pstring)+1);
char* data = (char*)malloc(strlen(pstring)+1);
if(data == NULL)
{
printf("malloc failure\n");
return -1;
}
printf("length is %d\n",strlen(pstring)+1);
strcpy(data,pstring);
printf("data is %s\n",data);
*pstr = tmp;
free(data);
while(1);
return 0;
}
原文:https://www.cnblogs.com/nowroot/p/13660647.html