改错题 在字符串的最前端加入n个*号,形成新串,
注意:字符串的长度允许为79。
请改正程序中的错误,使其能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
#include <string.h>
#include <conio.h>
void fun(char s[], int n)
{
char a[80], *p;
int i;
/********found********/
s = p;
for (i=0; i<n; i++)
a[i] = '*';
do
{
a[i] = *p;
i++;
/********found********/
___ì???___
} while (*p);
/********found********/
a[i] = '0';
strcpy(s, a);
}
main()
{
int n;
char s[80];
printf("\nEnter a string :");
gets(s);
printf("\nThe string %s\n", s);
printf("\nEnter n(number of *): ");
scanf("%d", &n);
fun(s, n);
printf("\nThe string after inster: %s\n", s);
}
第1处:s=p;应改为p=s;
第2处:应填p++;或++p;或p+=1或p=p+1
第3处:a[i]=’0’;应改为a[i]=’\0’;或a[i]=0;