69,382
社区成员
发帖
与我相关
我的任务
分享
int main()
{
char* buf="In order to thoroughly understand what makes Linux tick and why it works so well on a wide variety of systems, you need to delve deep into the heart of the kernel. The kernel handles all interactions between the CPU and the external world";
char* p;
char *tar="jkasdf";
char first[1024];
memset(first, 0, 1024);
p=strstr(buf,"makes Linux");
int nlen=p-buf;
strncpy(first,buf,nlen);
//first[nlen-1]='\0';
strcat(first,tar);
strcat(first,p+11);
//puts(first);
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main ()
{
char* buf="In order to thoroughly understand what makes Linux tick and why it works so well on a wide variety of systems, you need to delve deep into the heart of the kernel. The kernel handles all interactions between the CPU and the external world";
char* p;
char *tar="jkasdf";
char *first = (char *)malloc(strlen(tar)+strlen(buf)+1)
;
p=strstr(buf,"makes Linux");
int nlen=p-buf;
strncpy(first,buf,nlen);
first[nlen]='\0';
strcat(first,tar);
strcat(first,p+strlen("makes Linux"));
puts(first);
free(first);
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main ()
{
char* buf="In order to thoroughly understand what makes Linux tick and why it works so well on a wide variety of systems, you need to delve deep into the heart of the kernel. The kernel handles all interactions between the CPU and the external world";
char* p;
char *tar="jkasdf";
char first[10000];//你原来的数组太小了。你可以用char *first = (char *)malloc(strlen(tar)+strlen(buf)+1)
p=strstr(buf,"makes Linux");
int nlen=p-buf;
strncpy(first,buf,nlen);
first[nlen]='\0';//strcat得找到'\0'才可以运行,你这儿得加上。否则后面的strcat无法正确运行。
strcat(first,tar);
strcat(first,p+11);
puts(first);
return 0;
}