I need to get my program to open an .xls or txt file and count the occurance of each word in the file but the file that i`m trying to open is so big the program doesn't read it. here's the program that i used. please help!!!!
need help with word count C++ program
Started by waynejr25, Nov 01 2007 12:06 PM
2 replies to this topic
#1
Posted 01 November 2007 - 12:06 PM
|
|
|
#2
Posted 02 November 2007 - 08:52 AM
You don't appear to have included the program.
#3
Posted 02 November 2007 - 01:31 PM
here's the program can anyone help please it won't open the file.
#include<conio.h>
#include<process.h>
#include<stdio.h>
//#include<alloc.h>
#include<stdlib.h>
#include<string.h>
void insert(int);
void search(void);
char word[20],line[100];
struct node
{
char a[30];
int count;
struct node *ptr;
};
typedef struct node NODE;
NODE *head,*temp,*first=0;
void search()
{
char lline[50];
int i=0,j=0;
while(line[i]!='\0')
lline[i]=line[i++];
lline[i]='\0';
i=0;j=0;
while(lline[j]!='\0')
{
word[i++]=lline[j++];
if(lline[j]==' ')
{
word[i]='\0';
insert(i);
i=0;
j++;
}
}
}
void main()
{
char ch;
FILE *fp;
int i=0;
if((fp=fopen("sem1.txt","r"))==NULL)
{
printf("error opening file\n");
exit(0);
}
while((ch=fgetc(fp))!=EOF)
{
line[i++]=ch;
while((ch=fgetc(fp))!='\n'&&(ch!=EOF))
{
line[i++]=ch;
}
line[i]='\0';
i=0;
search();
}
fclose(fp);
fp=fopen("output.txt","w+");
temp->ptr=0;
temp=first;
while(temp!=0)
{
fprintf(fp,"%s\t\t%d\n",temp->a,temp->count);
temp=temp->ptr;
}
fclose(fp);
}
void insert(int c)
{
head=(NODE*) malloc(sizeof(NODE));
int i=0;
while(word[i]!='\0')
{
head->a[i]=word[i];
i++;
}
head->a[i]='\0';
head->count=c;
if(first!=0)
{
temp->ptr=head;
temp=head;
}
else
{
first=temp=head;
}
fflush(stdin);
}


Sign In
Create Account

Back to top









