#include <stdio.h>
#include <stdlib.h>
#include<time.h>
#define TRUE 1
#define FALSE 0
int main(int argc, char *argv[]) {
size_t myStrlen(char *string);
int myFind_char(char *string, char value);
int myFind2_char(char **strings, char value);
char *str = "12345678aaa";
printf("%d\n",myStrlen(str));
char * str2 = "a123456789";
printf("%d\n",myFind_char(str2,'0'));
char *str3[] = {"123","456","789",NULL};
printf("%d\n",myFind2_char(str3,'a'));
return 0;
}
/*
**求字符串的长度
*/
size_t myStrlen(char * string)
{
int length = 0;
while(*string++ != '\0')
{
length +=1;
}
return length;
}
/*
**在字符串中查找字符
*/
int myFind_char(char *string, char value)
{
if(string != NULL){
while(*string != '\0'){
if(*string++ == value){
return TRUE;
}
}
}
return FALSE;
}
/*
**在一组字符串中查找字符
*/
int myFind2_char(char **strings, char value)
{
char *string;
while((string = *strings++) != NULL)
{
while(*string != '\0')
{
if(*string++ == value)
{
return TRUE;
}
}
}
return FALSE;
}
C 求字符串的长度和查找字符
最新推荐文章于 2024-03-27 15:52:35 发布