fork(1) download
  1. #include <stdio.h>
  2.  
  3. #define NUM_WORDS 3
  4. #define WORD_SIZE 20
  5.  
  6. int main(void)
  7. {
  8. int i;
  9. char dictionary[NUM_WORDS][WORD_SIZE];
  10.  
  11. char word_fmt[20] = { '\0' };
  12. sprintf(word_fmt, "%%%ds", WORD_SIZE-1);
  13.  
  14. printf("Populate the dictionary with %d words:", NUM_WORDS);
  15. for (i = 1; i <= NUM_WORDS; i++) {
  16. printf("\n%d> ", i);
  17. scanf(word_fmt, &dictionary[i-1]);
  18. }
  19. putchar("\n");
  20.  
  21. printf("\nPrinting dictionary:\n");
  22. for (i = 0; i < NUM_WORDS; i++) {
  23. printf("[%d]: \"%s\"\n", i, dictionary[i]);
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 2056KB
stdin
ena duo tria
stdout
Populate the dictionary with 3 words:
1> 
2> 
3> 
Printing dictionary:
[0]: "ena"
[1]: "duo"
[2]: "tria"