Read numbers from an input file. Then sort them using any sorting algorithm. Then finally print the sorted numbers in another text file. I have tried the following code but it is not showing the output in another file.
#include "s.h";
#include<stdio.h>
int main(int argc, char *argv[])
{
int *a,num,i;
FILE *fp,*ft;
char s[5];
fp=fopen("input.txt","r");
sscanf(argv[1],"%d",&num);
printf("%d\n",num);
a=(int *)malloc(num*sizeof(int));
for(i=0;i<num;i++)
{
fgets(s,10,fp);
sscanf(s,"%d",a+i);
}
selection(a,num);
fclose(fp);
free(a);
ft=fopen("output.txt","w");
for(i=0;i<num;i++)
{
fprintf(ft,"%d",*(a+i));
fputs(s,ft);
fputs("\n",ft);
}
fclose(ft);
return 0;
}