1 Replies - 771 Views - Last Post: 22 January 2013 - 02:21 PM Rate Topic: -----

#1 ryan_0123456  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-January 13

Cannot write output text file to contain seperate lines,

Posted 22 January 2013 - 02:18 PM

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.

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




Is This A Good Question/Topic? 0
  • +

Replies To: Cannot write output text file to contain seperate lines,

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9580
  • View blog
  • Posts: 36,300
  • Joined: 12-June 08

Re: Cannot write output text file to contain seperate lines,

Posted 22 January 2013 - 02:21 PM

Do not open duplicate topics. Closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1