|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
I am in need for some assistance....I need to create a program that counts the number of words in certain program. The requirements for the program are
1) The program first reads a text from a txt file. 2)It counts how many times each word appears in the file 3) It displays the word and how many times it appears at the end... sorry for the bad explanation. Here's an example. It would call up a txt file such as test.txt This is a dog. This is a cat. The dog loves the cat!! In this case it needs to count like so This=1 is=2 a=2 dog.=1 That=1 cat.=1 The=1 dog=1 loves=1 the=1 cat!!=1 Although its an incomplete program, meaning that it counts "dog" and "dog." as two different words, my professor wants it to work out like so.... Another requirement is I combine these two programs I've created before Code:
#include<stdio.h>
#define SENTENCE_MAX 80
#define LIST_MAX 100
int main(){
int i,j;
char ch, sentence[SENTENCE_MAX], Slist[LIST_MAX][SENTENCE_MAX];
for(i=0;i<LIST_MAX;i++){
Slist[i][0]=0;
}
printf("*------- Sentence List Program -------* \n");
i=0;
do{
ch=getc(stdin);
j=0;
while((ch!=10)&&(ch!=EOF)&&(j<SENTENCE_MAX)){
sentence[j]=ch;
j++;
ch=getc(stdin);
}
sentence[j]=0;
strcpy(Slist[i],sentence);
i++;
}while(ch!=EOF);
printf("*------- Input file ---------* \n");
for(j=0;j<i;j++){
printf("%s \n",Slist[j]);
}
}
The other program I have to use is Code:
#include<stdio.h>
#define LIST_MAX 30
int main(){
int i, CHcount[LIST_MAX];
char ch, CHlist[LIST_MAX];
FILE *textin;
for(i=0;i<LIST_MAX;i++){
CHcount[i]=0;
CHlist[i]=0;
}
textin = fopen("test.txt","r");
do{
ch=fgetc(textin);
for(i=0;((???????)&&(???????));i++){
if(ch==CHlist[i])
break;}
if(CHcount[i]>0){
???????;
}
else{
?????? ;
??????;
}
}while((ch!=EOF));
for(i=0;((???????)&&(???????));i++){
printf("%c = %d \n",CHlist[i],CHcount[i]);
}
fclose(textin);
}
I need to combine these two codes in order to create a program that counts how many times a word is repeated....I'm just having a very difficult time becuase everything is already fixed by the professor and not much freedom is given. Any help is appreciated!!!!!!!! |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Java:Tutorial - Tic-Tac-Toe | John | Java Tutorials | 25 | 02-27-2008 06:41 PM |
| Dictonary Program | programmer 101 | Java Help | 9 | 07-01-2007 01:39 PM |
| How do I Program another Program? ! | bosco | General Programming | 1 | 06-15-2007 11:15 AM |
| Othello program!! 24 hours left! | siren | C and C++ | 1 | 06-14-2007 11:18 AM |
| Xav | ........ | 1357.94 |
| MeTh0Dz|Reb0rn | ........ | 1083.85 |
| WingedPanther | ........ | 919.18 |
| marwex89 | ........ | 906.86 |
| morefood2001 | ........ | 903.18 |
| John | ........ | 902.37 |
| Brandon W | ........ | 789.89 |
| chili5 | ........ | 312.39 |
| Steve.L | ........ | 264.99 |
| dcs | ........ | 240.34 |
Goal: 100,000 Posts
Complete: 83%