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;
}

New Topic/Question
This topic is locked



MultiQuote







|