hi all,
im very new to programming and require some help with an assignment. im trying to count the occurrences of words in a text file and output the results. this is what ive got so far any help would be greatly appreciated.
Code:#include "stdafx.h" #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <dos.h> #include <windows.h> int processFile(); int main() { processFile(); return 0; } int processFile() { char c , fname[25] , arr[1000][15]= {0} , oneword[15] ; int count[1000] = {0} , x = 0 , y , i = 0 , p ; FILE *file1; printf("\nenter file to process\n"); scanf("%s" , &fname); file1 = fopen(fname , "r"); if (file1 == NULL) { printf("error file missing"); //menu(); return 1; } while(!feof(file1)) { c = fscanf(file1 , "%s" , &oneword); for( i = 0 ; i < 1000 ; i++) //arr[i] != '\0' { if(strcmp(arr[i] , oneword)==0) { count[i]++; break; } } x++; strcpy(arr[x] , oneword); } for(p = 0 ; p < 1000 ; p++) { printf("%8s%11d\n" , arr[p] , count[p]); Sleep(100); } fclose(file1); system("pause"); return 0; }



LinkBack URL
About LinkBacks



