habe unter der "char word[80]"-Deklaration statt einem scanf, die Funktion fgets() versucht, um seeehr lange Eingaben zu unterdrücken die bei scanf möglich wären. Es funktioniert aber nicht.
Habe Manuals bereits durchgelesen bzw. div. yt-Videos: https://www.proggen.org/doku.php?id=c:lib:stdio:fgets
Code: Alles auswählen
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()  {
    //Declaring char-variable with max. lengt of 80 (indices)
    char word[80];
    fgets(word, 80, stdin);
    
    //For count from RHS, deduct 1 since strlen respective "length" counts from 1 instead 0.
    int length = strlen(word); int palindrome = 1; int leftcount = 0; int rightcount = length - 1;
    //Increase word letter-count from LHS, decrease word letter-count from RHS
    while(leftcount < rightcount)   {
        
        //Terminate if-statement as soos as left- & rightcount do not return the same (letters are case-sensitive)
        if(word[leftcount] != word[rightcount]) {
            palindrome = 0;
            break;
        }
        leftcount++; rightcount--;
    }
    //If palindrome = 1, meaning entered word is a palindrome => print "palindrome"
    if(palindrome)
        printf("palindrome\n");
    //If palindrome = 0, meaning entered word is not a palindrome => print "palindrome"
    else
        printf("not a palindrome\n");
    return 0;
    }gibt der Compiler eine falsche Bewertung aus ==> bei Eingabe "OttO" oder "HannaH", meint er das sei kein Palindrom, obwohl es eines ist.
Danke!
LG

