#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define TARGETSIZE 102400
#define PATTERNSIZE 3
void main()
{ char Target[TARGETSIZE];
printf("The letter input is made up of %d number\n", TARGETSIZE);
for(int i=0;i<TARGETSIZE;i++)
{ Target[i]=rand()%7+'a'; //产生随机字母组合
}
char Pattern[PATTERNSIZE];
printf("The pattern input is");
for(int j=0;j<PATTERNSIZE;j++)
{ Pattern[j]=rand()%7+'a';
printf("%s",Pattern[j]);
}
int target=0;
while('\0'!=Target[target])
{
int Temtarget=target;
for(int k=0;k<3;k++)
{if(Target[Temtarget++]!=Pattern[k])
break;
if(k==2)
printf("Native String Matching, pattern occurs with shift %u\n",target);
}
target++;
}
return 0;
}
结果编译的时候 出现segmentation fault( core dump)
第一个printf "The letter input is made up of %d number\n", TARGETSIZE); 正常输出
然后接下来的就没有输出了
使用了网上的解决办法 进入gdb模式 下 输入bt 显示的结果
warning: exec file is newer than core file.
[New LWP 4296]
warning: Can't read pathname for load map: Input/output error.
Core was generated by `./string'.
Program terminated with signal 11, Segmentation fault.
#0 0xb752fb8e in __printf_fphex (fp=0x0, info=0x0, args=0x0)
at ../stdio-common/printf_fphex.c:177
177../stdio-common/printf_fphex.c: No such file or directory.
(gdb) bt
#0 0xb752fb8e in __printf_fphex (fp=0x0, info=0x0, args=0x0)
at ../stdio-common/printf_fphex.c:177
#1 0x00000000 in ??
但是没有看明白 希望有人能够解释一下 多谢大家!
#include<string.h>
#include<stdlib.h>
#define TARGETSIZE 102400
#define PATTERNSIZE 3
void main()
{ char Target[TARGETSIZE];
printf("The letter input is made up of %d number\n", TARGETSIZE);
for(int i=0;i<TARGETSIZE;i++)
{ Target[i]=rand()%7+'a'; //产生随机字母组合
}
char Pattern[PATTERNSIZE];
printf("The pattern input is");
for(int j=0;j<PATTERNSIZE;j++)
{ Pattern[j]=rand()%7+'a';
printf("%s",Pattern[j]);
}
int target=0;
while('\0'!=Target[target])
{
int Temtarget=target;
for(int k=0;k<3;k++)
{if(Target[Temtarget++]!=Pattern[k])
break;
if(k==2)
printf("Native String Matching, pattern occurs with shift %u\n",target);
}
target++;
}
return 0;
}
结果编译的时候 出现segmentation fault( core dump)
第一个printf "The letter input is made up of %d number\n", TARGETSIZE); 正常输出
然后接下来的就没有输出了
使用了网上的解决办法 进入gdb模式 下 输入bt 显示的结果
warning: exec file is newer than core file.
[New LWP 4296]
warning: Can't read pathname for load map: Input/output error.
Core was generated by `./string'.
Program terminated with signal 11, Segmentation fault.
#0 0xb752fb8e in __printf_fphex (fp=0x0, info=0x0, args=0x0)
at ../stdio-common/printf_fphex.c:177
177../stdio-common/printf_fphex.c: No such file or directory.
(gdb) bt
#0 0xb752fb8e in __printf_fphex (fp=0x0, info=0x0, args=0x0)
at ../stdio-common/printf_fphex.c:177
#1 0x00000000 in ??
但是没有看明白 希望有人能够解释一下 多谢大家!