Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C - Probleme mit Strings, Casts & Co

Empfohlene Antworten

Veröffentlicht

#include<ctype.h>

#include<stdio.h>


char eingabefeld[30];

double zahl;

double puffer = 0;


do

{


    scanf("%s", &eingabefeld[]);


    if (isdigit(eingabefeld[]) == true);

    {


        zahl = (double)eingabefeld[]; // Typ Umwandlung in double


    }


    else


        switch (eingabefeld[])

        {


        // Test


        case'+':


            puffer += zahl;


            break;


        }

    printf("%lf", puffer); // Test Ausgabe



}

while (getchar() != 'b');


}

Wenn ich das Programm übersetzen möchte, meldet CodeBlocks 3 Fehler, die ich nicht ganz verstehe. :confused:

tzi\Desktop\test.c|8|error: expected unqualified-id before "do"|

tzi\Desktop\test.c|38|error: expected unqualified-id before "while"|

tzi\Desktop\test.c|40|error: expected declaration before '}' token|

||=== Build finished: 3 errors, 0 warnings ===|

Aufgabe des Programmes sollte sein:

Eingegebene Zeichen und Zahlen aussortieren (in Opperatoren und Zahlen) und dann auswerten. Mehr nicht! Ich brauch dieses System um einen guten Taschenrechner für die Konsole zu schreiben. :(

#include<ctype.h>

#include<stdio.h>


[B]int main (void)

{[/B]


    char eingabefeld[30];

    double zahl;

    double puffer = 0;


    do

    {


        scanf("%s", &eingabefeld[]);


        if (isdigit(eingabefeld[]) == true);

        {


            zahl = (double)eingabefeld[]; // Typ Umwandlung in double


        }


        else



            switch (eingabefeld[])

            {


                // Test


            case'+':


                puffer += zahl;


                break;


            }

        printf("%lf", puffer); // Test Ausgabe



    }

    while (getchar() != 'b');


[B]}[/B]

CodeBlocks meldet jetzt mehr Fehler!

Desktop\test.c||In function `int main()':|

tzi\Desktop\test.c|14|error: expected primary-expression before ']' token|

tzi\Desktop\test.c|16|error: expected primary-expression before ']' token|

tzi\Desktop\test.c|19|error: expected primary-expression before "double"|

tzi\Desktop\test.c|19|error: expected `)' before "double"|

tzi\Desktop\test.c|23|error: expected primary-expression before "else"|

tzi\Desktop\test.c|23|error: expected `;' before "else"|

||=== Build finished: 6 errors, 0 warnings ===|

Zeile 14:

Die eckigen Klammern müssen weg. Überhaupt darfst du eckige Klammern ohne "Inhalt" nur bei der Deklaration eines Arrays benutzen.

Zeile 16:

isdigit kann nur einzelne Zeichen prüfen, kein ganzes Array auf einmal.

Und das Semikolon am Ende muss weg.

Zeile 19:

Diese "Typumwandlung" ist Unsinn. Schau dir mal die Funktion atof an.

Zeile 26:

switch funktioniert nicht mit Zeichenketten.

Zeile 16:

du kannst in C nicht auf == true vergleichen (außer du hast true irrgendwo definiert)

da in C keine boolischen Variablen vorgesehn sind.

d.h. du müsstest if (isdigit(eingabefeld) != 0 ) oder if (isdigit(eingabefeld)) schreiben

Zeile 23:

Fehlen bei deinem else die geschweiften Klammern

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.