I have a file where i have some records like that:
test one; test one; test one; 1
test two; test two; test two; 2
I need to sort those records according to the last number, so in my previous example the second record should be at the first place, since 2>1. For this, i'm trying to add each record to an array and then apply an insertion sort algorithm. I have some problems adding each part to an array, here is my current effort:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLEN 100
int main() {
char one[MAXLEN] = {};
char two[MAXLEN] = {};
char three[MAXLEN] = {};
int st[MAXLEN] = {};
int i, j;
FILE * fpointer = fopen("clients.txt", "r");
for (i = 0; i < MAXLEN; i++) {
fscanf(fpointer, "%s%s%s%d", &one[i], &two[i], &three[i], &st[i]);
}
for (j = 0; j < MAXLEN; j++) {
printf("%s", one[i]);
}
fclose(fpointer);
return 0;
}
In this example, i tried to add each field to an array, the second for loop is just a test to check whether or not data is being added to the array properly, but it's not.
oneis just a string / char array, likechar one[MAXLEN][MAXSIZE]&once you put the 2D char array.