473,563 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Concordance of Word

3 New Member
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 2997
numberwhun
3,509 Recognized Expert Moderator Specialist
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
3498
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 the moment the printed output is usually going to Word. It's turning into an unholy mess, because I'm having to prepare umpteen different Word...
3
6107
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 done this? Does it seem possible? I followed the instructions from a sample on the Microsoft knowledge base but it only seems to work when creating...
2
13494
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 execute a MailMerge to create mailing labels or customized letters. A label name known to MS Word MailMerge mailing label wizard may be used or a...
7
6229
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 user and populated (with info from an Access database) at run-time, then saved as Word documents. The program I have coded works fine -- it does...
4
12420
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 this: can Access create the document and place it as an OLE object to the relevant table? Any help is greatly appreciated. Ricky
2
4943
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> #include <ctype.h> #include <string.h> #include <stdlib.h> struct word { struct word *left; /* tree to the left */ struct word *right; /* tree to...
0
1903
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 PreviousToken(Previous word) and frequency and probability From text file and put each one in cell in table For example if the text file content is "Every man has...
5
2530
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 PreviousToken(Previous word)) from multube files and get frequency of both. it can get for single word but double word give error line 50, in...
1
4368
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 text) or a subsequent addition of text, insert, to the document. as this is going to be used along side other com opened applications Excel power...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.