师兄们帮忙看下我哪里有问题,编程好了,运行出错
吃茫茫 人气新星 2015-09-07 21:00:33
1485 9 0

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';


问题来自: 编程题真题

共 9 个回答

    嘿嘿大人 一代宗师 3599天前

    你的LEN没有看到定义啊?或者你发个完整的程序?

    吃茫茫 人气新星 3599天前

    回复 嘿嘿大人:那个定义好了的哈

    #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) ;

    }


    嘿嘿大人 一代宗师 3599天前

    回复 吃茫茫:我运行起是没有问题的,你把报错发出来吧

    吃茫茫 人气新星 3599天前

    回复 嘿嘿大人:怎么发报错。。。就是输入完了之后就停止运行了


    嘿嘿大人 一代宗师 3599天前

    while(a[LEN])这是个死循环一直都没有变化,a【LEN】没有变化

    吃茫茫 人气新星 3599天前

    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';

    blob.png

    最佳答案

    嘿嘿大人 一代宗师 3599天前

    {

    a[i]=b[j++];

    }

    k++;

    改为,赋值语句写错了吧b[j++]=a[i];

    吃茫茫 人气新星 3599天前

    回复 嘿嘿大人:就是!!!!!!!!!啊啊啊啊啊啊啊啊啊

    嘿嘿大人 一代宗师 3599天前

    回复 吃茫茫:赋值语句一定要搞清楚方向,估计你是看错了,仔细点,加油吧

您还没有登录,所以不能回复该问题