Facebook
From Miczeq, 7 Years ago, written in C.
Embed
Download Paste or View Raw
Hits: 310
  1. // WczytywanieC.cpp : Defines the entry point for the console application.
  2. //
  3. #define _CRT_SECURE_NO_WARNINGS
  4. #include "stdafx.h"
  5. #include <conio.h>
  6. #include <cstring>
  7. #include <malloc.h>
  8. #include <ctype.h>
  9.  
  10. int main()
  11. {
  12.         char title[256];
  13.         char nick[256];
  14.  
  15.         int points = 0;
  16.         int id = 0;
  17.  
  18.         FILE* file;
  19.  
  20.         if ((file = fopen("quiz.txt", "r")) == NULL)
  21.         {
  22.                 printf("\n Podana sciezka jest nieprawidlowa.\n");
  23.         }
  24.  
  25.         fgets(title, sizeof(title), file);
  26.         strtok(title, "\n");
  27.  
  28.  
  29.         fgets(nick, sizeof(nick), file);
  30.         strtok(nick, "\n");
  31.  
  32.         printf("%s\n%s\n", title, nick);
  33.  
  34.         char buffer[256];
  35.  
  36.         while (!feof(file))
  37.         {
  38.                 fgets(buffer, sizeof(buffer), file);
  39.                 strtok(buffer, "\n");
  40.                
  41.                 char* question = (char*)malloc(sizeof(char) * strlen(buffer) + 1);
  42.                 strcpy(question, buffer);
  43.  
  44.                 fgets(buffer, sizeof(buffer), file);
  45.                 strtok(buffer, "\n");
  46.  
  47.                 char* a = (char*)malloc(sizeof(char) * strlen(buffer) + 1);
  48.                 strcpy(a, buffer);
  49.  
  50.                 fgets(buffer, sizeof(buffer), file);
  51.                 strtok(buffer, "\n");
  52.  
  53.                 char* b = (char*)malloc(sizeof(char) * strlen(buffer) + 1);
  54.                 strcpy(b, buffer);
  55.  
  56.                 fgets(buffer, sizeof(buffer), file);
  57.                 strtok(buffer, "\n");
  58.  
  59.                 char* c = (char*)malloc(sizeof(char) * strlen(buffer) + 1);
  60.                 strcpy(c, buffer);
  61.  
  62.                 fgets(buffer, sizeof(buffer), file);
  63.                 strtok(buffer, "\n");
  64.  
  65.                 char* d = (char*)malloc(sizeof(char) * strlen(buffer) + 1);
  66.                 strcpy(d, buffer);
  67.  
  68.                 char goodAnswer;
  69.                 fscanf(file, "%c\n", &goodAnswer);
  70.  
  71.                 printf("\n%d)%s\na)%s\nb)%s\nc)%s\nd)%s\n", ++id, question, a, b, c, d);
  72.  
  73.                 char answerCharacter;
  74.                 scanf("\n%c", &answerCharacter);
  75.  
  76.                 if (tolower(answerCharacter) == tolower(goodAnswer))
  77.                 {
  78.                         printf("\nPrawidlowa odp\n");
  79.                         points++;
  80.                 }
  81.                 else
  82.                 {
  83.                         printf("\nNieprawidlowa odp\n");
  84.                 }
  85.         }
  86.  
  87.         printf("\nQuiz zakonczony, Twoje punkty to: %d/%d", points, id);
  88.  
  89.         fclose(file);
  90.  
  91.         _getch();
  92.     return 0;
  93. }
  94.  
  95.