求教 去除字符串后面的“*”(不能用到strlen strcpy strcat等函数)
比如 *k*k*
处理后变为 *k*k
#include<conio.h>
#include<stdio.h>
void fun( char a[])
{
char *p=a ;
while(*p!='\0')
{
++p ;
}
--p ;
while(*p--=='*' )
{
*p='\0' ;
*a--=*p ;}
}
main()
{
clrscr();
printf("input string:");
gets(a);
fun(a);
puts(a);
}
我自己编的~~ 不知道哪错了
大侠门帮我改改把~
main函数是给定的
子函数 形式为 void fun( char a[])
问题点数:50、回复次数:10Top
1 楼chenhu_doc(^0^纯一狼^0^ 看书看到大笑,直到不能自已)回复于 2006-07-02 23:27:48 得分 0
#include <stdio.h>
void main()
{
char ch[6] = "*k*k*";
int i=0;
printf("%s\n",ch);
while( '\0' != ch[i])
++i;
if( '*'== ch[i-1] )
ch[i-1] = '\0';
printf("%s\n",ch);
}Top
2 楼chenhu_doc(^0^纯一狼^0^ 看书看到大笑,直到不能自已)回复于 2006-07-02 23:28:16 得分 0
lz写的代码中错误太多了!
还是要好好看书!Top
3 楼llf_hust()回复于 2006-07-02 23:28:30 得分 0
#include<conio.h>
#include<stdio.h>
void fun( char a[])
{
char *p=a ;
while(*p != '\0')
{
++p ;
}
--p ;
while(*p=='*' )
{
*p='\0' ;
p--;
}
}
main()
{
char a[20];
printf("input string:");
gets(a);
fun(a);
puts(a);
}
Top
4 楼yingge(...木脑壳...)回复于 2006-07-02 23:47:52 得分 0
汗,又来后面的*了。。。Top
5 楼liyueliyu()回复于 2006-07-02 23:53:15 得分 0
想到就做啊~ 开来我还要多练习啊Top
6 楼Wolf0403(废人:独活十年~心如刀割)回复于 2006-07-03 00:44:37 得分 0
http://community.csdn.net/Expert/TopicView3.asp?id=4855898Top
7 楼jixingzhong(瞌睡虫·星辰)回复于 2006-07-03 15:03:17 得分 0
楼主修改你的程序:
void fun( char a[])
{
char *p=a ;
while(*p++ != '\0');
--p ;
while(*p == '*')*p-- = '\0' ; //注意 -- 的位置,另外不要操作原来的指针 ....
}
Top
8 楼happytang(一只叫苏格拉底的猪)回复于 2006-07-03 21:47:49 得分 0
在你的基础上改地
#include<conio.h>
#include<stdio.h>
void fun( char a[])
{
char *p=a ;
while(*p!='\0')
{
++p ;
}
--p ;
while(*p--=='*')
//{
*(++p)='\0' ;
//*a--=*p ;}
}
void main()
{
char a[50];
//clrscr();
printf("input string:");
gets(a);
fun(a);
puts(a);
}Top
9 楼Kvci(看了不笑就没小JJ同时又比较长的昵称__——————————————————————————————)回复于 2006-07-04 09:28:01 得分 0
void tre(char *s)
{
if(*s=='\0')return;
tre(s+1);
if(*s=='*'&*(s+1)=='\0') *s='\0';
else return;
}
main()
{
char *p="asd*asd***";
tre(p);
printf("\n%s",p);
}Top
10 楼mLee79()回复于 2006-07-04 09:44:03 得分 0
#include <stdio.h>
void foobar( char* s )
{
char* p = s-1;
for( ; *s ; ++s ) if( *s != '*' ) p = s;
p[1] = 0;
}
int main()
{
char buff[100];
while( 1 )
{
scanf( "%s" , buff );
foobar( buff );
printf( "%s\n" , buff );
}
return 0;
}Top




