hello all,
I have to write the code to read the file line by line and sort its words in alphabetical order n store into another file, i have done with the feathing the line from one file but strugling with the sorting part can anybody suggest how should i move forward..
here is code i have written:
#include<stdio.h>
#include<conio.h>
#define max_size 80
int main()
{
FILE *fp,*fp1;
int i;
char file1[50],file2[50],buffer[80];
int c;
clrscr();
printf("\n Enter File 1:\n");
scanf("%s",file1);
printf("\n Enter file 2: ");
scanf("%s",file2);
fp = fopen(file1,"r");
fp1 = fopen(file2,"w" );
if(fp == NULL)
{
printf("\n Error in opening the file 1.");
}
if(fp1==NULL)
{
printf("\n Error in opening the file 2.");
}
//fatching line frm file one n storing in to the array Buffer.
if (fgets(buffer,max_size,fp)!=NULL);
{
printf("%s",buffer);
/******************************************************From Here I am strugling ...
*****************************************************/
/* for (i=0;i<80 ;i++)
{
if(buffer[i] == " ")
{
printf("\n harshal");
break;
}
puts(temp);
printf("%s\n",buffer);
*/
}
printf("%s\n",temp);
//fputs(buffer,fp1);
//c=getc(fp);
}
fclose(fp);
fclose(fp1);
getch();
}
}