Hello, I'm writing this program for an academical assignment that is why i need to use the bubble sort algorithm, even though, from what i undersand, is not the most suitable solution. I have tried to go on with my code but it's still not working and i'm getting more and more confused because i don't have really clear in my mind how to handle pointers... Here is what i have done but i'm sure it's completely wrong
/* Program that takes a text file as input and produces an output file that has all the original lines in alphabetical order */
#include <stdio.h>
#include <string.h>
#define SIZE 30
int main()
{
char name[ SIZE ]; /* Data records */
FILE \*fpPtr; /\* fpPtr = sorted\_file.txt pointer \*/
/\* fopen opens file; exits program if file cannot be opened \*/
if ( ( fpPtr = fopen( "sorted\_file.txt", "r" ) ) == NULL ) {
printf( "File could not be opened\\n" );
} /\* End if \*/
/\* Read records from file \*/
else {
printf( "%s\\n", "Name" );
fscanf( fpPtr, "%s", name );
/\* While not end of file \*/
while( !feof( fpPtr ) ) {
printf( "%s\\n", name );
fscanf( fpPtr, "%s", name );
} /\* End while \*/
fclose( fpPtr ); /\* fclose closes the file \*/
} /\* End else \*/
/* sort */
for ( pass = 1; pass < SIZE; pass++ ){ /* loop to cotrol passes */
for ( counter = 0; counter < SIZE - 1; counter ++ ){ /* loop to control number of comparesons per pass */
if ( *name [ counter ] > *name [ counter + 1 ] ) {
hold = *name[ counter ];
*name[ counter ] = *name[ counter + 1 ];
*name[ counter + 1 ] = hold;
} /* End if */
}/* end of inner for */
}/* end of outer for */
return 0; /\* Indicates that the program terminated successfully \*/
} /* End Main */