程序改错——字符移动——初学者
改错:
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 );
}
|