I would like to write a program in c# that reads words from an input text file and writes an output text file containing lines each consisting of two comma separated values identifying the word and the number of times it has occurred in the input text file.
I would like the output text file to be sorted so that more common words appear before less common words. If words appear the same number of times they should be sorted alphabetically.
For example if the input file contains the words:
testing testing one two three
then I would like the output file to be:
testing,2
one,1
three,1
two,1
If that makes sense,so far I have written code which reads the text file, but need to work out how to complete this.
I would like the output text file to be sorted so that more common words appear before less common words. If words appear the same number of times they should be sorted alphabetically.
For example if the input file contains the words:
testing testing one two three
then I would like the output file to be:
testing,2
one,1
three,1
two,1
If that makes sense,so far I have written code which reads the text file, but need to work out how to complete this.
#include<stdio.h> int main(){ char str[70]; FILE *p; if((p=fopen("string.txt","r"))==NULL){ printf("\nUnable t open file string.txt"); exit(1); } while(fgets(str,70,p)!=NULL) puts(str); fclose(p); return 0; }