Commit 7be23875 by glkink

inimesed.txt

25
12:00 0
12:02 1
12:03 4
12:05 5
12:06 6
12:08 7
12:09 9
12:10 12
12:11 13
12:12 15
12:13 18
12:15 16
12:16 14
12:17 10
12:18 7
12:21 8
12:23 10
12:25 11
12:26 12
12:30 11
12:32 9
12:37 5
12:39 2
12:40 1
12:41 0
 
parent f392187b
Showing with 48 additions and 0 deletions
#include <stdio.h>
#include <stdlib.h>
struct inimesed
{
char aeg[20];
int inimesteArv;
} info[50];
void main()
{
struct inimesed ajutine;
FILE *fail;
int i = 0, n, j;
char t;
fail = fopen("inimesed.txt", "r");
if (fail == NULL)
{
printf("Ei saa faili avada! \n");
exit(0);
}
fscanf(fail, "%d", &n);
while (i < n)
{
fscanf(fail, "%s%d", info[i].aeg, &info[i].inimesteArv);
t = fgetc(fail);
i++;
}
for (i = 1; i < n; ++i)
{
for (j = 0; j < n - i; j++)
{
if (info[j + 1].inimesteArv > info[j].inimesteArv)
{
ajutine = info[j];
info[j] = info[j + 1];
info[j + 1] = ajutine;
}
}
}
for (i = 0; i < n; i++)
{
printf("%d %s\n", info[i].inimesteArv, info[i].aeg);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment