Mit rumgefrickel lernt man recht fix, finde ich. Hier stieß ich trotz des Wikis (ich verstand nur Bahnhof - mal wieder

Mir ist folgendes Problem untergekommen:
1. Die Do-While-Schleife soll aufhören sobald <enter> (und nur <enter>) zur Eingabe gedrückt wird.
2. Die Schleife soll bei einer falschen Eingabe (Buchstaben oder Zahlen außerhalb des Wertebereichs) die Fehlermeldung ausgeben.
Code: Alles auswählen
#include <stdlib.h>
#include <stdio.h>
int add( int Summand_Eins, int Summand_Zwei, int *memory_address )
{
return *memory_address = Summand_Eins + Summand_Zwei;
}
int main()
{
//system("cls"); /* Spezifisch!! cls= Windows, Linux = clear beim debuggen auskommentiert*/
printf ("\n########################################################\n");
printf ("dies ist eine Additions-Funktion:");
printf ("\n########################################################\n\n");
int Summe=0, Summand=0, i=0, j=0, m=0, Summanden_Liste[j];
char Eingabe[] = {"0,0,0,0,0,0,0,0,0,0"};
do
{
printf ("Summand %.2d: ", i+1);
scanf ("%s", &Eingabe);
Summand = atoi(Eingabe);
if (Summand == 0) /* Wie prüfe ich hier, ob eine Zahl oder ein Buchstabe vorliegt? */
{
printf ("bitte eine g%cltige Zahl eingeben\n", 129);
}
else
{
add( Summand, Summe, &Summe );
i++;
Summanden_Liste[j] = Summand;
j++;
}
}
while (Summand != 0); /* Hier soll geprüft werden, ob ein reines <enter> auftrat, dass zum beenden des Programms führen soll*/
printf ("\nDie Gesamtsumme aus den Zahlen");
for (int k = 0; k < j-1; k = k+1)
{
if (j>=2) {printf(" ");}
printf( "%d", Summanden_Liste[k]);
if (k<j-2)
{
printf (",");
}
else
{
if (k=j-1)
{
printf (" und %d", Summanden_Liste[k]);
}
}
}
printf(" ist: %d\n", Summe);
return EXIT_SUCCESS;
}
Habt ihr weitere Tipps zur Verbesserung/Optimierung des Programms?