#include "stdio.h"
#include <string>
void main()
{
int i;
int j;
int times = 0;
int cnt;
char org[100] = "asdfasdfasdfasdfasdfasdf";
char target[15] = "asd";
char *porg = org;
char *ptar = target;
for (i = 0; i < strlen(org); i++)
{
cnt = 0;
if (*(porg + i) == *ptar)
{
for (j = 0; j <= strlen(ptar); j++)
{
if (*(porg + i + j) == *(ptar + j))
{
cnt++;
}
}
if (cnt == strlen(ptar))
{
times++;
printf("find! start position: org[%d], times: %d\n", i, times);
}
}
}
}
自己测试BUG。自己改正,然后告诉我。
#include <string>
void main()
{
int i;
int j;
int times = 0;
int cnt;
char org[100] = "asdfasdfasdfasdfasdfasdf";
char target[15] = "asd";
char *porg = org;
char *ptar = target;
for (i = 0; i < strlen(org); i++)
{
cnt = 0;
if (*(porg + i) == *ptar)
{
for (j = 0; j <= strlen(ptar); j++)
{
if (*(porg + i + j) == *(ptar + j))
{
cnt++;
}
}
if (cnt == strlen(ptar))
{
times++;
printf("find! start position: org[%d], times: %d\n", i, times);
}
}
}
}
自己测试BUG。自己改正,然后告诉我。
努力学习C、C++、LINUX、ORACLE、ENGLISH,累死为止。