1

以下のコードは xcode で正常にコンパイルされますが、Microsoft Visual Studio に渡すと、大量のエラーが発生します。

    void openfile(int mapArray[MAX_HEIGHT][MAX_WIDTH], int *interest, int *dimension1, int *dimension2)
    { 
    int counter = 0;
    char buffer;
    int rowss, colss;
    *interest = 0;

    FILE *f;
    f = fopen(FILENAME, "r");
    if (f==NULL) {
            printf("Map file could not be opened");
            return 0;
    }


    // create char array the dimensions of the map
    fscanf(f, "%d %d" , dimension1, dimension2 );
    // printf("%d %d\n" , dimensions[0], dimensions[1]);


    // Reads the spaces at the end of the line till the map starts
    buffer=fgetc(f);
    while (buffer!='*') {
            buffer=fgetc(f);
    }

    // Read the txt file and print it out while storing it in a char array
    while (buffer!=EOF) {

            mapArray[rowss][colss]=buffer;

            colss++;

            // Count up the points of interest
            if (((buffer>64)&&(buffer<90))||(buffer=='@') ) {
                                    counter++;

                            }

            // resets column counter to zero after newline
            if (buffer=='\n') {
                    colss=0;
                    rowss++;
            }
            buffer=fgetc(f);
    }

    // Closes the file
    fclose(f);
    *interest=counter;

    }

すべてのエラーを引き起こしているのはどの部分ですか? コンパイルしようとすると、このエラーのリストが表示されます

前もって感謝します。

4

1 に答える 1

0

差し迫った問題がいくつか見られます。まず、それらを使用する前に初期化していないrowssためcolss、それらには任意の値が含まれる可能性があります。

次に、ファイルの終わりを検出できるように をfgetc()返します。inta を使用しcharて戻り値を保持することにより、標準ライブラリとの契約を破ることになります。

第 3 に、関数が返すように指定されている(つまり、何も返さない)0にもかかわらず、ファイル名を開くことができなかった場合は a を返します。void

これらは間違いなく、コンパイラーが検出した 3 つのエラーであり、他にもある可能性があります。より徹底的な分析のために、質問と共にエラー リストを投稿する必要があります。

于 2012-10-14T05:12:30.640 に答える