Thank you for your time again. I'll look up qsort().Now that is how my code looks like after I did as you said.
Code:
#include<stdio.h>
#include<string.h>
#include<locale.h>
int main ()
{
setlocale(LC_ALL, "");
FILE *pt;
FILE *pt2;
long size=100;
pt=fopen("C:\\002.txt","r");
pt2=fopen("C:\\003.txt","w");
char (*a)[50];
do{
if(getc(pt)=='\n')
size++;
}while(!feof(pt));
rewind(pt);
printf("%d",size);
a = malloc ( size* sizeof *a );
int i,j;
for(i=0;i<size;i++) fscanf(pt,"%s",a[i]);
char *temp;
for(i=0;i<(size-1);i++)
for(j=0;j<(size-1);j++)
if(strcoll(a[j], a[j+1]) >0 )
{
char *temp = a[j];
*a[j] = a[j+1];
*a[j+1] = temp;
}
for(i=0;i<size;i++)
fprintf(pt2,"%s\n",a[i]);
getch();
return 0;
}
in the
Code:
a[j] = a[j+1];
a[j+1] = temp;
lines I had a "incompatible types in assignment" error so I add the "*"'s.There are two problems.
First, now it doesnt sort. It just changes the first letter of each word with a weird character. And second, my first problem continues. The size... It still counts more than there is.Do you see anything wrong with this part:
Code:
do{
if(getc(pt)=='\n')
size++;
}while(!feof(pt));