Bubble sorting IP address
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;
|