师兄们帮忙看下我哪里有问题,编程好了,运行出错
void fun (char a[], char b[], int n)
{
int i,j=0;
while(a[LEN])
{
for(i=0;i<LEN;i++)
if((i+1)!=n)
{
a[i]=b[j++];
}
}
b[j]='\0';
回复 嘿嘿大人:那个定义好了的哈
#include <stdio.h>
#include <string.h>
#define LEN 20
void fun (char a[], char b[], int n)
{
int i,j=0;
while(a[LEN])
{
for(i=0;i<LEN;i++)
if((i+1)!=n)
{
a[i]=b[j++];
}
}
b[j]='\0';
}
main( )
{ char str1[LEN], str2[LEN] ;
int n ;
void NONO ( );
printf("Enter the string:\n") ;
gets(str1) ;
printf("Enter the index of the char deleted:") ;
scanf("%d", &n) ;
fun(str1, str2, n) ;
printf("The new string is: %s\n", str2) ;
NONO() ;
}
void NONO ( )
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
char str1[LEN], str2[LEN] ;
int i, n ;
FILE *rf, *wf ;
rf = fopen("in.dat","r") ;
wf = fopen("out.dat","w") ;
for(i = 0 ; i < 10 ; i++) {
fscanf(rf, "%s %d", str1, &n) ;
fun(str1, str2, n) ;
fprintf(wf, "%s\n", str2) ;
}
fclose(rf) ;
fclose(wf) ;
}
void fun (char a[], char b[], int n)
{
int i,j=0,k=0;
while(a[k])
{
for(i=0;i<LEN;i++)
if(i!=(n-1))
{
a[i]=b[j++];
}
k++;
}
b[j]='\0';