maikonsx

Vetores.c

Jun 22nd, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <locale.h>
  6.  
  7. typedef struct{
  8.  
  9.     char VetorFacil[20];
  10.  
  11. }VETORES;
  12.  
  13.     void carregaPalavrasFacil(VETORES *vetorFuncFacil);
  14.     void mostraPalavrasFacil();
  15.     void pontuacao();
  16.  
  17. void main(){
  18.  
  19.     int op, i;
  20.     VETORES vetorFuncFacil[10] = {'a','b','c','d','e','f','g','h','i','j'};
  21.  
  22.     printf("Escolha o nivel em que deseja jogar: \n");
  23.             puts("1) Facil");
  24.             puts("2) Medio");
  25.             puts("3) Dificil");
  26.             puts("4) Ajuda");
  27.             fflush(stdin);
  28.             scanf("%i", &op);
  29.                
  30.            
  31.             switch(op){
  32.                 case 1: {
  33.                     carregaPalavrasFacil(vetorFuncFacil);
  34.                     break;
  35.                 }
  36.                 case 2: {
  37.                     printf("Sim\n");
  38.                     break;
  39.                 }
  40.                 case 3: {
  41.                     printf("Sim\n");
  42.                     break;
  43.                 }
  44.                 case 4:{
  45.                     puts("Ajuda!");
  46.                     break;
  47.                 }
  48.                 default: {
  49.                     puts("Opção Inválida!");
  50.                     break;
  51.                 }
  52.             }
  53. }
  54. void carregaPalavrasFacil(VETORES *vetorFuncFacil){
  55.  
  56.     int i, cont = 0, pegalinha, para;
  57.     char line[20];
  58.     FILE *arquivo;
  59.     arquivo = fopen("facil.txt", "r");
  60.     if(arquivo == NULL){
  61.         printf("Arquivo Inválido!\n");
  62.         exit(1);
  63.     }else{
  64.         for(cont = 0; cont < 20; cont++){
  65.             int numero = rand() % 20;
  66.             do{
  67.                 if(pegalinha == numero){
  68.                     fgets(line, sizeof(line), arquivo);
  69.                     strcpy((*vetorFuncFacil).VetorFacil, line);
  70.                     para = 1;
  71.                 }else{
  72.                     pegalinha++;
  73.                 }
  74.             }while(para != 1);
  75.         }
  76.     }
  77.  
  78.      for(i=0; i<=10; i++){
  79.         printf("%s\n", vetorFuncFacil[i].VetorFacil);
  80.     }
  81.  
  82.     fclose(arquivo);
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment