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){
printf("\n");
scanf("%99s", &s2[0]);
int b = strcmp(s, s2);
if(b == 0){
printf("\nRichtige Antwort\n");
fragen ++;
rantworten++;
}else{
printf("\nFalsche Antwort\n");
fragen++;
}
}
a++;
}
if(a % 2 == 0){
printf("%c", temp);
}else {
strcat(s, temp);
}
}
printf("Von %d Fragen waren %d richtig!", fragen, rantworten);
fclose(fp);
}
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?
1776
Thank you very much for every answer.
User contributions licensed under CC BY-SA 3.0