
C语言,输入一个字符串和一个字符,就从该字符最后出现的位置输出字符串中的字符否则返回空指针NULL
我这么写为啥运行不出结果。#include<stdio.h>char*match(char*s,charch);intmain(void){charch,str[80],...
我这么写为啥运行不出结果。
#include<stdio.h>
char *match( char *s, char ch );
int main( void )
{
char ch, str[80], *p = NULL;
printf( "Please Input the string : \n" );
scanf( "%s", str );
getchar();
ch = getchar();
if( ( p = match( str, ch ) ) != NULL )
printf( "%s\n", p );
else
printf( "Not Found\n" );
return 0;
}
char *match( char *s, char ch )
{
char *k = NULL;
while( *s != '\0' )
{
if( *s == ch )
k = s;
else
s++;
}
if( k != NULL )
return(k);
return (NULL);
} 展开
#include<stdio.h>
char *match( char *s, char ch );
int main( void )
{
char ch, str[80], *p = NULL;
printf( "Please Input the string : \n" );
scanf( "%s", str );
getchar();
ch = getchar();
if( ( p = match( str, ch ) ) != NULL )
printf( "%s\n", p );
else
printf( "Not Found\n" );
return 0;
}
char *match( char *s, char ch )
{
char *k = NULL;
while( *s != '\0' )
{
if( *s == ch )
k = s;
else
s++;
}
if( k != NULL )
return(k);
return (NULL);
} 展开
2个回答
展开全部
match函数修改如下。
char *match( char *s, char ch )
{
char *k = NULL;
while( *s != '\0' )
{
if( *s == ch )
k = s;
s++;
}
if( k != NULL )
return(k);
return (NULL);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询