Click here to Skip to main content
16,004,944 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to parse a CString: 1,1,E1,0.13060,-0.40193,-0.90631 - Parsing Comma Delimted Strings Pin
Iain Clarke, Warrior Programmer24-Feb-09 12:36
Iain Clarke, Warrior Programmer24-Feb-09 12:36 
QuestionHow to read names from a file and sort them in alphabetical order Pin
raeiko24-Feb-09 7:49
raeiko24-Feb-09 7:49 
AnswerRe: How to read names from a file and sort them in alphabetical order Pin
Stuart Dootson24-Feb-09 8:04
professionalStuart Dootson24-Feb-09 8:04 
GeneralRe: How to read names from a file and sort them in alphabetical order Pin
David Crow24-Feb-09 9:14
David Crow24-Feb-09 9:14 
GeneralRe: How to read names from a file and sort them in alphabetical order Pin
Stuart Dootson24-Feb-09 9:16
professionalStuart Dootson24-Feb-09 9:16 
AnswerRe: How to read names from a file and sort them in alphabetical order Pin
David Crow24-Feb-09 9:47
David Crow24-Feb-09 9:47 
AnswerRe: How to read names from a file and sort them in alphabetical order Pin
tyr200025-Feb-09 1:40
tyr200025-Feb-09 1:40 
AnswerRe: How to read names from a file and sort them in alphabetical order Pin
raeiko25-Feb-09 11:24
raeiko25-Feb-09 11:24 
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 */

Questionusing tokenize to extract numbers and strings from a mixture of number and characters comma-delimited Pin
mrby12324-Feb-09 7:37
mrby12324-Feb-09 7:37 
AnswerRe: using tokenize to extract numbers and strings from a mixture of number and characters comma-delimited Pin
Stuart Dootson24-Feb-09 8:03
professionalStuart Dootson24-Feb-09 8:03 
GeneralRe: using tokenize to extract numbers and strings from a mixture of number and characters comma-delimited Pin
mrby12324-Feb-09 8:07
mrby12324-Feb-09 8:07 
GeneralRe: using tokenize to extract numbers and strings from a mixture of number and characters comma-delimited Pin
Stuart Dootson24-Feb-09 8:28
professionalStuart Dootson24-Feb-09 8:28 
GeneralRe: using tokenize to extract numbers and strings from a mixture of number and characters comma-delimited Pin
mrby12324-Feb-09 9:04
mrby12324-Feb-09 9:04 
GeneralRe: using tokenize to extract numbers and strings from a mixture of number and characters comma-delimited Pin
Stuart Dootson24-Feb-09 9:14
professionalStuart Dootson24-Feb-09 9:14 
GeneralRe: using tokenize to extract numbers and strings from a mixture of number and characters comma-delimited Pin
mrby12324-Feb-09 12:17
mrby12324-Feb-09 12:17 
GeneralRe: using tokenize to extract numbers and strings from a mixture of number and characters comma-delimited Pin
Stuart Dootson24-Feb-09 12:44
professionalStuart Dootson24-Feb-09 12:44 
GeneralRe: using tokenize to extract numbers and strings from a mixture of number and characters comma-delimited Pin
mrby12324-Feb-09 12:49
mrby12324-Feb-09 12:49 
QuestionControlling Serial and parallel ports Pin
isolanya24-Feb-09 6:06
isolanya24-Feb-09 6:06 
QuestionRe: Controlling Serial and parallel ports Pin
Roger Stoltz24-Feb-09 6:26
Roger Stoltz24-Feb-09 6:26 
QuestionIs crystal Report 7.0 supports in VS2008 Pin
P A N K A J24-Feb-09 4:49
P A N K A J24-Feb-09 4:49 
QuestionRe: Is crystal Report 7.0 supports in VS2008 Pin
Rajesh R Subramanian24-Feb-09 5:10
professionalRajesh R Subramanian24-Feb-09 5:10 
AnswerRe: Is crystal Report 7.0 supports in VS2008 Pin
P A N K A J24-Feb-09 5:13
P A N K A J24-Feb-09 5:13 
GeneralRe: Is crystal Report 7.0 supports in VS2008 Pin
Rajesh R Subramanian24-Feb-09 5:16
professionalRajesh R Subramanian24-Feb-09 5:16 
QuestionVRML in OpenGL and MFC Pin
Pompeyo24-Feb-09 3:48
Pompeyo24-Feb-09 3:48 
AnswerRe: VRML in OpenGL and MFC Pin
Stuart Dootson24-Feb-09 3:58
professionalStuart Dootson24-Feb-09 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.