
C - Porovnanie String & Integer
Zdravím, potreboval by som pomocť porovnávaním sringu z integerom. Ide o to, že mám súbor s najlepším skóre, a potrebujem ho porovnať a aktuálnym a následne ak je to potrebné aktualizovať. Problém je v porovnávaní:
if (skore < lineArray[x]) lineArray[x]=skore;
Nakoľko sa mi to nedarí vyriešiť, tak som ďalej zatiaľ nepokračoval. Zatiaľ mám toto:#include <stdio.h>
#include <string.h>
int main()
{
int x = 0, i, lineCount = 3, skore=1;
char line[4], *lineArray[lineCount];
FILE *file = fopen("file.txt", "r" );
if (file == NULL){
printf("Cannot open file\n");
return 1;
}
rewind(file);
printf("Top skore:\n");
while (fgets(line, sizeof(line), file) != NULL) {
lineArray[x] = malloc(strlen(line));
strcpy(lineArray[x], line);
/*if (skore < lineArray[x]) lineArray[x]=skore;*/
printf("%d. %s", x+1, lineArray[x]);
x++;
}
printf("\n");
system("PAUSE");
return(0);
}