Bubble sorting IP address

Discussion in 'C' started by czm, Apr 24, 2008.

  1. czm

    czm New Member

    Joined:
    Apr 24, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Am trying to a program that bubble sorts IP address. the IP address line has some string after which should remain in the same line after the bubble sort.

    Code:
    ypedef struct ipaddress
    
    {
    
        short int w, x, y, z;
    
    } ipaddress;
    
    typedef struct logStruct
    
    {
    
        ipaddress ip;
    
        char * as_line;
    
    } log;
    
    void getIP(ipaddress * ip, char * as_line)
    
    {
        as_line+=3;
    
        ip->w = atoi(strtok(as_line, "."));
    
        ip->x = atoi(strtok(NULL, "."));
    
    
        ip->y = atoi(strtok(NULL, "."));
    
    
        ip->z = atoi(strtok(NULL, " "));
    
      
    sortArray = calloc(sizeof(log *) , numLines);
    
        for (counter = 0; counter < numLines; counter++)
        {
            sortArray[counter] = calloc(sizeof(log),1);
            sortArray[counter]->as_line = calloc(sizeof(char),500);
            fgets(sortArray[counter]->as_line,500,myfile);
            strcpy(buffer,sortArray[counter]->as_line);
            getIP(&(sortArray[counter]->ip),buffer);
    	/*sortArray[counter]->as_line*/
    	}
    	 	
       bubbleSort(sortArray, numLines);
    
    void bubbleSort(log * * array, int numLines)
    
    {
    
    log * temp_store;
    
    	int i, j;
    
    	
        for (i = 0; i < numLines; i++)
    
            for (j = 0; j < length-1; j++)
    
            {
    
                
        
    
                  tempPointer = array[j];
    
                    array[j] = array[j+1];
    
                    array[j+1] = tempPointer;
     
    Last edited by a moderator: Apr 25, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice