samedi 14 novembre 2020

Getting random positions correctly from a C array

first of all, I'm a newbie in C so that I've been struggling to learn some simple things. That's the issue I want to pick random questions from the array questions, I need to create the following logic process, the program is going to start asking any question from the array, and after the user reply the question I want to save the reply in one array and the question in another, I want to save the questions already asked because I don't want the program to repeat the question so that I'll save it and check if the questions have already been done, and the answers I will save because I'll compare to another array with the right questions into it. Here's my code

#include <stdio.h>
#include <stdlib.h>
#include <time.h>


int main()
{
  char questions[] = { 'a', 'b', 'c','d'};
  char reply[4];
  char aux[4];

  int i;
  time_t t;
  srand((unsigned)time(&t));

  do{

    printf("%c\n", questions[rand()%4]);
    scanf("%s\n",reply[i]);

    aux[i] = array[rand()%4];


  }while( i < 4);



  for(int i = 0; i < 4; i++)
  {
    printf("%c\n",aux[i]);
  }


  return 0;
}

The problem is that the script stops in the first question, I can't manage to get the other ones, so please what am I doing wrong here?




Aucun commentaire:

Enregistrer un commentaire