Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. struct node
  2. {
  3. char word[46];
  4. struct node* prev;
  5. struct node* next;
  6. };
  7.  
  8. struct node *d[52];
  9. struct node *conductor;
  10. for (int i=0; i<sizeof(d); i++)
  11. {
  12. d[i]= (struct node *) malloc( sizeof(struct node) );
  13. }
  14. FILE* in = fopen("dictionary","r");
  15. int first, second, i = 0; /* i=index*/
  16. char w[46]; /* w= word of maximum length 45 */
  17.  
  18.  
  19. while ((fputs (w,in))!= EOF)
  20. {
  21. first = atoi(&w[0]) - 97;
  22. second = atoi(&w[1]) - 97;
  23. if (second < 14)
  24. {
  25. i=first*2;
  26. }
  27. else
  28. {
  29. i=first*2+1;
  30. }
  31.  
  32. if (d[i]->next != NULL)
  33. {
  34. strcpy(d[i]->word,w);
  35. d[i]->next=NULL;
  36. }
  37. else
  38. {
  39. conductor= d[i];
  40. conductor->prev=(struct node *) malloc( sizeof(struct node) );
  41. conductor=conductor->prev;
  42. conductor->next=d[i];
  43. d[i]=conductor;
  44. strcpy(d[i]->word,w);
  45. }
  46.  
  47. }
  48.  
  49. fclose (in);
  50.  
  51. return false;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement