Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #define ARRAYSIZE 10
  4. int numberOfWordsInDict(char **dict){
  5.     int nwords = 0;
  6.     for (int i = 0; i < 10; i++){
  7.         if (dict[i] != 0)
  8.             nwords++;
  9.     }
  10.     return nwords;
  11. }
  12.  
  13. void addWord(char **dict, char *word){
  14.     int i = numberOfWordsInDict(dict);
  15.     dict[i] = word;
  16. }
  17.  
  18. void printDict(char **dict){
  19.     if (dict[0] == 0)
  20.         printf("Empty!\n");
  21.     else{
  22.         for (int i = 0; i < ARRAYSIZE; i++)
  23.             printf("%s\n", dict[i]);
  24.     }
  25. }
  26.  
  27. void main(){
  28.     char* dict[ARRAYSIZE] = {};
  29.     char word[256];
  30.     printf("Add a word in the dictionary: ");
  31.     scanf(" %s", &word);
  32.     addWord(dict, word);
  33.     printDict(dict);
  34.     /* h.javan.hemmat@tue.nl*/
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement