Originally Posted by
brewbuck
You should not have to seek. In fact, I don't see how you could, since this data is line-based and lines can be of different lengths.
u can seek in the file with variable string lengths..... just use ftell() and store the position before and after seeking and store them in a long int..... string compare and rewrite......
a part of u r code would be......
Code:
c = '' ;/*nocharacter*/
while( ! feof ( file_poin ) )
{
first_word_start = ftell ( file_poin ) ;
fgets ( first_name , file_poin ) ; /*first name*/
first_word_end = ftell( file_poin ) ;
fgets ( second_name , file_poin ) ; /*second name*/
second_word_end = ftell( file_poin ) ;
if ( strcmp ( first_name , second_name ) > 0 )
{
fseek( file_poin , first_word_start , 0 ) ;
fputs ( first_name , file_poin );
while( ftell ( file_poin ) != first_word_end )
{
putc( c , file_poin );
}
fputs ( second_name , file_poin ) ;
while( ftell ( file_poin ) != second_word_end )
{
putc( c , file_poin );
}
rewind( file_poin );
}
}
as only swapping is taking place there wont be extra spaces or alphabets after each swap