Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailem 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);
}
Jsou zobrazeny jen nové odpovědi. Zobrazit všechny
Předmět Autor Datum
Tento funguje... #include <stdio.h> #include <string.h> int main() { int x = 0, i, lineCount = 3, s…
LenJa 14.12.2014 19:37
LenJa
Teď nějak na první pohled nevidím, v čem je rozdíl.
Wikan 14.12.2014 19:59
Wikan
Pravdu-povediac ho tam nevidím ani ja...Skrátka som ten zdroják napísal odznovu a funguje, bez zmien…
LenJa 14.12.2014 20:05
LenJa
Tak to jsi ho po nějaké změně nepřekompiloval. poslední
Wikan 14.12.2014 20:08
Wikan

Tento funguje...

#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);
    printf("%d. %s", x+1, lineArray[x]);
    x++;
} 
   printf("\n\n\n");
   system("PAUSE");
   return(0);
}

Zpět do poradny Odpovědět na původní otázku Nahoru