fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. void random(char list[][32], char *key, int size){
  7. int i = rand()%size;
  8. printf("choice %d\n",i);
  9. printf("choice key is %s\n", list[i]);
  10. strcpy(key, list[i]);
  11. }
  12.  
  13. int main(void){
  14. char list[5][32], key1[32], word[32];
  15. int count = 0;
  16. srand(time(NULL));
  17.  
  18. while(1){
  19. printf("Enter word : ");
  20. fgets(word, sizeof(word), stdin);
  21. if(strcmp(word, "END\n")==0)
  22. break;
  23. if(count < 5 && 1==sscanf(word, "VERTEX %s", key1)){
  24. strcpy(list[count++],key1);
  25. }
  26. }
  27. random(list, key1, count);
  28. printf("choice key : %s\n", key1);
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 2012KB
stdin
VERTEX No.1
VERTEX No.2
VERTEX No.3
VERTEX No.4
VERTEX No.5
END
stdout
Enter word : Enter word : Enter word : Enter word : Enter word : Enter word : choice 3
choice key is No.4
choice key : No.4