C applet - define an interface (function) by yourself, and implement the function (find the number of occurrences of the string abcd)

/char *p = "abcd1111abcd222abcd3333" Please find the number of occurrences of the string abcd
//Requirement 1: Please define an interface (function) yourself and implement the function; 70 points
//Requirement 2: Write test cases. 30 points
/*
//Input: the string
to be searched, the
output result


*/
//int cltClient_rev(void *handle, unsigned char *buf, int *buflen)
//Don't believe what others send you memory address is available
int getCout(char *str, char *substr, int *count)
{
int rv = 0;
char *p = str; int ncout = 0; if (str==NULL || substr== NULL | | count==NULL) { rv = -1; printf("func getCout()check (str==NULL || substr== NULL || count==NULL) err:%d \n" , rv); return rv; } do  { p = strstr(p, substr);











if (p == NULL) // jump out if not found
{
break;
}
else 
{
ncout++;
p = p + strlen(substr);
}

} while (*p != '\0');

*count  = ncout;
printf("ncout:%d\n", ncout);
return rv;


}

void main()
{

int ret = 0;

        char *p = NULL;

char *p = "abcd1111abcd222abcd3333";
int ncout = 0;
char *subp = "abcd";
ret = getCout(p, subp, &ncout);
if (ret != 0)
{
printf("func getCout() err:%d \n", ret);
return ;
}
printf("coutn:%d \n", ncout);
system("pause");
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325809671&siteId=291194637