Guest User

Untitled

a guest
Jan 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. typedef struct TreeOfWords{
  2. char* s;
  3.  
  4.  
  5. }TreeOfWords;
  6.  
  7. void InsertWord(TreeOfWords*** words, char *s, int *countOfItems) {
  8.  
  9. TreeOfWords *p = (TreeOfWords*)malloc(sizeof(TreeOfWords));
  10. p->s = (char*)malloc(strlen(s)+1);
  11. strcpy(p->s, s);
  12.  
  13. *words = (TreeOfWords**)realloc(words, (*countOfItems+1)*(sizeof(TreeOfWords*))); //Erroe occurs here
  14. (*words)[(*countOfItems)] = p;
  15.  
  16. }
  17.  
  18. int main()
  19. {
  20. int count = 0;
  21. TreeOfWords** words = NULL;
  22. char* pch = 'hello'; // actually i am using here while loop and many strings, but here will be just one word
  23. InsertWord(&words, pch, 0);
  24.  
  25. *words = realloc(words, (*countOfItems+1)*(sizeof(TreeOfWords*)));
Add Comment
Please, Sign In to add comment