.exe停止工作循环问题?

时间:2015-03-16 14:15:33

标签: c convolution

我正在尝试编写一个打开2个文档的方法,并从文档中写入的数据中创建卷积和。但是,我得到.exe停止工作错误,这是一个常见的事情。我无法弄清楚如何解决问题。

这是我的代码:

void convolution(char fileName1[],char fileName2[]){
    FILE *filepointer1;
    FILE *filepointer2;
    int counter = 0;
    float xf;
    setbuf(stdout,NULL);
    int oops= 0;

        filepointer1 = fopen(fileName1,"r");
        if(filepointer1 != NULL){
                    while(fscanf(filepointer1,"%f",&xf)==1){ //Size Finder for 1
                        counter++;
                    }
                    fclose(filepointer1);
        } else{
                printf("Error in reading %s\n", fileName1);
        }
        int size1 = counter;

        //Second Data
        filepointer2 = fopen(fileName2,"r");
        counter = 0;

        if(filepointer2 != NULL){
                    while(fscanf(filepointer2,"%f",&xf)==1){ //Size Finder for 2
                        counter++;
                    }
                    fclose(filepointer2);
        } else{
                printf("Error in reading %s\n", fileName2);
                }

        int size2 = counter;
        int maxsize = size1+size2-1;

        //array creations
        float holder2[maxsize];
        int i=0;

        for(i=size2;i<maxsize-1;i++){ // fill with zeros

            holder2[i]=0.0;
                }
        float holder1[maxsize];
        int x=0;

        for(x=size1;x<maxsize-1;x++){ // fill with zeros
            holder1[x]=0.0;
        }

        // Now read files
        setbuf(stdout,NULL);

        filepointer1 = fopen(fileName1,"r");
        counter =0;
        if(filepointer1 != NULL){
                                while(fscanf(filepointer1,"%f",&xf)==1){ //Size Finder for 1
                                    holder1[counter]=xf;
                                    printf("%f\t",holder1[counter]);
                                    counter++;
                                }
                                fclose(filepointer1);
                    } else{
                            printf("Error in reading %s\n", fileName1);
                            }

        filepointer2 = fopen(fileName1,"r");
        counter =0;
        if(filepointer2 != NULL){
                            while(fscanf(filepointer2,"%f",&xf)==1){ //Size Finder for 2
                                holder2[counter] = xf;
                                counter++;


                            }

                            fclose(filepointer2);
                } else{

                        printf("Error in reading %s\n", fileName2);
                        }

        //now perform convolution

        float convolved[maxsize];

        int k=0;
        int j =0;
        for(k=0;k<maxsize;k++){
            for(j=0;j<k+1;j++){
            convolved[k] = convolved[k] + holder1[j]*holder2[k-j];
        }
        }
//convolved is the result array now print it

            FILE *printpointer;
            char fileNameprinted[] = "D:\Convolved.txt";
            printpointer = fopen(fileNameprinted,"w");
            int z =0;
            for (z=0;z<maxsize;z++){
                fprintf(printpointer,"%f\n",convolved[i]);
                printf("%f\n",convolved[i]);
            }

            fclose(printpointer);

}

0 个答案:

没有答案