What is the problem in the following program?


I've started to write a new short program to train to handle with files, but I didnt get where the mistake is in my program. Here is the code:

int main(){

    int temp;
    FILE *fp;

    fp = fopen("questions.txt", "r");

    if(fp == NULL){
        printf("Datei konnte NICHT geöffnet werden.\n");
    }else {
        printf("Datei konnte geöffnet werden.\n");
        int a = 0;
        char s[100];
        char s2[100];
        int fragen = 0;
        int rantworten = 0;

        while((temp = fgetc(fp)) != EOF){
            if(temp == '\n'){
                if(a > 0){
                    scanf("%99s", &s2[0]);

                    int b = strcmp(s, s2);

                    if(b == 0){
                        printf("\nRichtige Antwort\n");
                        fragen ++;
                        printf("\nFalsche Antwort\n");

            if(a % 2 == 0){
                printf("%c", temp);
            }else {
                strcat(s, temp);

    printf("Von %d Fragen waren %d richtig!", fragen, rantworten);

return 0;

and here is the output:

Datei konnte ge÷ffnet werden.
Wie hei├ƒt der h├Âchste Berg?
Process returned -1073741819 (0xC0000005)   execution time : 3.047 s
Press any key to continue.

as you can see is the program do not going into the scanf command.

If you need it here is the textdocument:

Wie heißt der höchste Berg?
Mount Everest
In welchem Jahr erklärten die Vereinigten Staaten von Amerika ihre Unabhängigkeit?

Thank you very much for every answer.

asked on Stack Overflow Jan 6, 2020 by Tim Bergener • edited Jan 6, 2020 by lurker

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0