Jump to content

need help with word count C++ program

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
waynejr25

waynejr25

    Newbie

  • Members
  • Pip
  • 2 posts
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!!!!

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You don't appear to have included the program.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
waynejr25

waynejr25

    Newbie

  • Members
  • Pip
  • 2 posts
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);

}