游客:  注册 | 登录 | 搜索 | 帮助
3s地带



标题: 程序改错——字符移动——初学者
非洲小白脸
疾风
Rank: 4Rank: 4



UID 7890
精华 0
积分 254
帖子 63
现金 244
贡献值 0
阅读权限 40
注册 2007-8-24
程序改错——字符移动——初学者
改错:
fun函数的功能是把 s 串中所有的字符前移一个位置,串中的第一个字符移到最后。

例如: s 串中原有的字符串为: Abcdefg,调用该函数后,s串中的内容则为:bcdefgA。



共有2行有错误,每个/*****found*****/以下的部分有1行。请寻找错误行并分别改正。其它内容不许改动;不许增加行,也不许删除行。



#include <conio.h>
#include <stdio.h>
#include <string.h>
#define N 81
/*************found************/
fun ( char s )
{ int i, j, n ;
char t ;
n=strlen(s) ;
t=s[0] ;
for(i=0 ;i<n-1 ;i++)
/*************found************/
s[i+1]=s ;
s[n-1]=t ;
}
main( )
{ char a[ N ] ;
clrscr();
printf ( "Enter a string : " );
gets ( a );
printf ( "The original string is : " );
puts( a );
fun ( a );
printf ( "The string after modified : ");
puts ( a );
}

顶部
你讲先
疾风
Rank: 4Rank: 4



UID 7699
精华 0
积分 421
帖子 134
现金 411
贡献值 0
阅读权限 40
注册 2007-8-24
#include <conio.h>
#include <stdio.h>
#include <string.h>
#define N 81
/*************found************/
fun ( char s )//错误1:参数是字符串,应用指针,改为(char*s)
{ int i, j, n ;
char t ;
n=strlen(s) ;
t=s[0] ;
for(i=0 ;i<n-1 ;i++)
/*************found************/
s[i+1]=s;//错误2:应把后面的值赋给前面,改为s=s[i+1] ;
s[n-1]=t ;
}
main( )
{ char a[ N ] ;
clrscr(); //错误3:这个没有定义,应去掉
printf ( "Enter a string : " );
gets ( a );
printf ( "The original string is : " );
puts( a );
fun ( a );
printf ( "The string after modified : ");
puts ( a );
}

  
顶部


 
当前时区 GMT+8, 现在时间是 2009-1-9 15:03 清除 Cookies - 联系我们 - 3S地带 - Archiver - WAP - 赣ICP备07006302号
Powered by Discuz! 5.5.0  © Processed in 0.026147 second(s), 6 queries , Gzip enabled