C: error in srand(time(NULL);

Asked

Viewed 1,221 times

2

I’m playing a little game in C(college project) and I’m finding an error in main, follow:

int main () {
    int x, y, i, j, linha, cnt=1, jl=0, jc=0, jogada_a=0, jogada_b=0;
    char coluna, jogador;
    srand(time(NULL));
    x = (rand() % 5) +2;
    y = (rand() % 5) +2;
    gerar();
    matriz[x][y] = '0';
}

Error calls for team statement:

error: 'time' was not declared in this Scope

2 answers

7

The inclusion of headers:

#include <stdlib.h>  /* rand(), srand() */
#include <time.h>    /* time() */
  • @gfleck you suggested an issue in that question which deviates the author’s own opinion of the answer. If you do not mind, post as another answer if you help the author of the question (AP).

-1

After function srand(time(NULL)) you need to use FOR.

  • When possible, exemplify how the code will look

Browser other questions tagged

You are not signed in. Login or sign up in order to post.