// WczytywanieC.cpp : Defines the entry point for the console application. // #define _CRT_SECURE_NO_WARNINGS #include "stdafx.h" #include #include #include #include int main() { char title[256]; char nick[256]; int points = 0; int id = 0; FILE* file; if ((file = fopen("quiz.txt", "r")) == NULL) { printf("\n Podana sciezka jest nieprawidlowa.\n"); } fgets(title, sizeof(title), file); strtok(title, "\n"); fgets(nick, sizeof(nick), file); strtok(nick, "\n"); printf("%s\n%s\n", title, nick); char buffer[256]; while (!feof(file)) { fgets(buffer, sizeof(buffer), file); strtok(buffer, "\n"); char* question = (char*)malloc(sizeof(char) * strlen(buffer) + 1); strcpy(question, buffer); fgets(buffer, sizeof(buffer), file); strtok(buffer, "\n"); char* a = (char*)malloc(sizeof(char) * strlen(buffer) + 1); strcpy(a, buffer); fgets(buffer, sizeof(buffer), file); strtok(buffer, "\n"); char* b = (char*)malloc(sizeof(char) * strlen(buffer) + 1); strcpy(b, buffer); fgets(buffer, sizeof(buffer), file); strtok(buffer, "\n"); char* c = (char*)malloc(sizeof(char) * strlen(buffer) + 1); strcpy(c, buffer); fgets(buffer, sizeof(buffer), file); strtok(buffer, "\n"); char* d = (char*)malloc(sizeof(char) * strlen(buffer) + 1); strcpy(d, buffer); char goodAnswer; fscanf(file, "%c\n", &goodAnswer); printf("\n%d)%s\na)%s\nb)%s\nc)%s\nd)%s\n", ++id, question, a, b, c, d); char answerCharacter; scanf("\n%c", &answerCharacter); if (tolower(answerCharacter) == tolower(goodAnswer)) { printf("\nPrawidlowa odp\n"); points++; } else { printf("\nNieprawidlowa odp\n"); } } printf("\nQuiz zakonczony, Twoje punkty to: %d/%d", points, id); fclose(file); _getch(); return 0; }