473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Concordance of Word

3
i am a c programming beginner and i am trying to Create a concordance of Word Count for a text File in c programming but my code isn't working.please can u help me out.here is my code:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. struct word {
  6. struct word *left; /* tree to the left */
  7. struct word *right; /* tree to the right */
  8. char *WORD;
  9. int count;
  10. }word;
  11. static struct word *root = NULL;
  12. void memory_error(void)
  13. {
  14. fprintf(stderr, "not enough memory\n");
  15. exit(8);
  16. }
  17. char *fp(char *fp)
  18. {
  19. char *p; 
  20. p = (char*)malloc((unsigned) (strlen(fp) + 1));
  21. if (p == NULL)
  22. memory_error();
  23. strcpy(p, fp);
  24. int compword(const void *WORD1, const void *WORD2);
  25. return (p);
  26. }
  27. void enter(struct word **word, char *WORD)
  28. {
  29. int result; 
  30. char *fp(char *); 
  31. if ((*word) == NULL) {
  32. (*word) = ((word*)malloc(sizeof(struct word)));
  33. if ((*word) == NULL)
  34. {printf("not enough mem");
  35. exit(1);
  36. }
  37. }
  38. (*word)->left = NULL;
  39. (*word)->right = NULL;
  40. (*word)->WORD = fp(WORD);
  41. (*word)->count=1;
  42. return;
  43. }
  44. result = strcmp((*WORD)->word,WORD);
  45. if (result == 0);
  46. {
  47. (*word)->count+=1;
  48. return;
  49. }
  50. if (result < 0);
  51. {{
  52. enter(&((*word)->right),WORD) ;
  53. else
  54. enter(&((*word)->left),WORD);
  55. }
  56. void scan(char *name)
  57. {
  58. char WORD[100];
  59. int index; 
  60. int ch; 
  61. FILE *f; 
  62. f = fopen(name, "r");
  63. if (f == NULL) {
  64. fprintf(stderr, "Unable to open %s\n", name);
  65. exit(8);
  66. }
  67. while (1) {
  68. ch = fgetc(f);
  69. if (isalpha(ch) || (ch == EOF))
  70. break;
  71. }
  72. if (ch == EOF)
  73. break;
  74. WORD[0] = ch;
  75. for (index = 1; index < sizeof(WORD); ++index) {
  76. ch = fgetc(f);
  77. if (!isalpha(ch))
  78. break;
  79. WORD[index] = ch;
  80. }
  81. WORD[index] = '\0';
  82. enter(&root, WORD);
  83. }
  84. fclose(f);
  85. }
  86. void print_tree(struct word *top)
  87. {
  88. if (top == NULL)
  89. return; 
  90. print_tree(top->left);
  91. printf("%s\n", top->WORD);
  92. print_tree(top->right);
  93. }
  94. int main(int argc, char *argv[])
  95. {
  96. if (argc != 2) {
  97. fprintf(stderr, "Wrong number of parameters\n");
  98. fprintf(stderr, " on the command line\n");
  99. fprintf(stderr, "Usage is:\n");
  100. fprintf(stderr, " words 'file'\n");
  101. exit(8);
  102. }
  103. scanf(argv[1]);
  104. print_tree(root);
  105. return (0);
  106. }
  107.  
would be very grateful for your help.
Dec 13 '07 #1
1 2982
numberwhun
3,509 Expert Mod 2GB
First, you failed to use the necessary Code Tags when posting code into the forums. I have added them to the post for you. Please know that code tags are required for all code posted to the forums.

Second, you have posted your thread in the Member Introductions forum when it is clearly a "C" question. There are many forums here on TSDN devoted to specific topics and there is on for C/C++, where this thread should have been posted.

I am moving the this thread there now.

Regards,

Jeff
Dec 13 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
3
by: Yohancef Chin | last post by:
Hi, Being fairly new to .NET I am looking for a way to call MS Word from an event on a webform, and after the user is finished save that created document to an SQL Server database. Has anyone...
2
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to...
7
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
2
by: beanie | last post by:
i am a beginer in c programming and i am trying to Create a Concordance of Word Count for a Text File but my code is not working.pls can anyone helpme out.here is my code: #include <stdio.h>...
0
by: alivip | last post by:
I write code to get most frequent words in the file I won't to implement bigram probability by modifying the code to do the following: How can I get every Token (word) and ...
5
by: alivip | last post by:
How can I get every Token (word) and PreviousToken(Previous word) From multube files and frequency of each two word my code is trying to get all single word and double word (every Token (word) and...
1
by: dittytwo | last post by:
Hi there The below code works if you don't try to do anything to the word document which is great (Not :D) I am having problems with the context command both text (i.e initial document with no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.