Der nicht initialisierte Wert wurde durch eine Stapelzuweisung erstellt

==13890== Conditional jump or move depends on uninitialised value(s)
==13890==    at 0x4E7E4F1: vfprintf (vfprintf.c:1629)
==13890==    by 0x4E878D8: printf (printf.c:35)
==13890==    by 0x400729: main (001.c:30)
==13890==  Uninitialised value was created by a stack allocation
==13890==    at 0x400617: main (001.c:11)

Die Zeile, auf die verwiesen wird:

int limit = atoi(argv[1]);

Ich bin nicht sicher, wie ich das beheben soll. Ich habe versucht, auf Stackoverflow und Google zu suchen, aber ich konnte die Lösung nicht finden.

Der Code (aus dem Revisionsverlauf):

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    if (argc != 2) {
        printf("You must pass a single integer\n");
        exit(1);
    }

    int limit = atoi(argv[1]); 
    int numbers[limit / 2];
    int count = 0;
    int i;
    for (i = 3; i < limit; i++) {
        if (i % 3 == 0 || i % 5 == 0) {
            numbers[count] = i;
            count++;
        }
    }

    int sum = 0;

    for (i = 0; i < count; i++) {
        sum += numbers[i];
    }

    printf("The sum is: %d\n", sum);

    return 0;
}

Antworten auf die Frage(2)

Ihre Antwort auf die Frage