用指针寻找指定字符串Write a function to search a character pointed by
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/09/21 20:38:10
用指针寻找指定字符串
Write a function to search a character pointed by a pointer,in a character sequence.Return the pointer pointing to the found character.
Eg1:search for ‘C’ in “ABCDEF”,return the pointer point to ‘C’.
Eg2:search for ‘Z’ in “ABCDEF”,return a NULL pointer.
The function header is given by:
char *findC (char const *source,char const *obj);
Write a function to search a character pointed by a pointer,in a character sequence.Return the pointer pointing to the found character.
Eg1:search for ‘C’ in “ABCDEF”,return the pointer point to ‘C’.
Eg2:search for ‘Z’ in “ABCDEF”,return a NULL pointer.
The function header is given by:
char *findC (char const *source,char const *obj);
#include "stdafx.h"
#define MAX_LEN 128
char *findC (char const *source, char const *obj)
{
char *p = (char *)source;
if(source == NULL || obj == NULL)
return NULL;
while(*p!='\0'){
if(*p == *obj)
return p;
else p++;
}
return NULL;
}
//Eg1: search for ‘C’ in “ABCDEF”, return the pointer point to ‘C’.
//Eg2: search for ‘Z’ in “ABCDEF”, return a NULL pointer.
void main()
{
char s1[]="ABCDEF";
//char c = 'C';
char c = 'Z';
char *value = NULL;
value = findC(s1,&c);
if(value!=NULL)
printf("%c\n",*value);
else
printf("NULL\n");
}
#define MAX_LEN 128
char *findC (char const *source, char const *obj)
{
char *p = (char *)source;
if(source == NULL || obj == NULL)
return NULL;
while(*p!='\0'){
if(*p == *obj)
return p;
else p++;
}
return NULL;
}
//Eg1: search for ‘C’ in “ABCDEF”, return the pointer point to ‘C’.
//Eg2: search for ‘Z’ in “ABCDEF”, return a NULL pointer.
void main()
{
char s1[]="ABCDEF";
//char c = 'C';
char c = 'Z';
char *value = NULL;
value = findC(s1,&c);
if(value!=NULL)
printf("%c\n",*value);
else
printf("NULL\n");
}
英语翻译Write a function that takes three arguments:a character
Write a function which copies one file to another.Have the f
高中英语造句.用a branch of,according to,search sth for sb,search sp
英语翻译Write a function that dynamically allocates an array of
Write as a function of x, if 0
数学题中write a simpler function agrees with the given function
"click on a character to get started!
英语翻译His leg was hurt by a sharply pointed branch when he fel
C语言字符串计数Write a program that reads an English statement from
You are about to write a poem ,aren't you =A poem ___ (by yo
build a character是什么意思
write a letter=write to sb?