fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. typedef struct {
  5. char na[64];
  6. int stts[6];
  7. } Monster;
  8. Monster creMonster(){
  9. int i,k;
  10. Monster tmp;
  11. k = rand()%8+4;
  12. int a = 'a' + rand()%26;
  13. for(i=0;i<k;i++) tmp.na[i] = 'a' + rand()%26;
  14. tmp.na[k] = '\0';
  15. for(i=0;i<6;i++) tmp.stts[i] = rand()%255+1;
  16. return tmp;
  17. }
  18. void priMonster(Monster m){
  19. printf("%12s : ",m.na);
  20. for(int i=0;i<6;i++)
  21. printf("%3d ",m.stts[i]);
  22. printf("\n");
  23. }
  24. int main(){
  25. srand((unsigned)time(NULL));
  26. int i, n;
  27. Monster *monsters;
  28. scanf("%d",&n);
  29. monsters = (Monster *)malloc(sizeof(Monster)*n);
  30. if(monsters == NULL){
  31. printf("ERROR\n");
  32. return 0;
  33. }
  34. for(i=0;i<n;i++){
  35. monsters[i] = creMonster();
  36. printf("%03d ",i+1);
  37. priMonster(monsters[i]);
  38. }
  39. free(monsters);
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5304KB
stdin
5
stdout
001         xblki  : 115 228 140 144 161  90 
002       xkwiawf  : 103  88  81  19 202  85 
003   xmrwpdhxbod  :  47 214   7 146 254 100 
004         wtobj  :  63 243 121 136  72  90 
005    wdjlgslkio  :  70  10  68 215   9  40