Skip to content

Instantly share code, notes, and snippets.

@pinpox
Created November 29, 2018 16:41
Show Gist options
  • Save pinpox/7f3c44c873fa1be64ad5b40adf6bf4de to your computer and use it in GitHub Desktop.
Save pinpox/7f3c44c873fa1be64ad5b40adf6bf4de to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
void s_reverse(char *str);
int isPalindropme(char *a);
void s_reverse(char *str)
{
// Leeren und NULL string abfangen
if (str == 0 || *str == 0)
return;
//Start an Anfang setzen
char *start = str;
// Ende auf Anfang + Laenge -1 (wegen \0 )
char *end = start + strlen(str) - 1;
char temp;
while (end > start) {
//tauschen
temp = *start;
*start = *end;
*end = temp;
++start;
--end;
}
}
int isPalindropme(char *a)
{
char b[strlen(a)];
strcpy(b, a);
s_reverse(b);
return strcmp(a, b) ==0;
}
int main(int argc, char *argv[])
{
if (argc != 2) {
printf("Error, no argument supplied");
return 1;
}
char *n = argv[1];
printf("Reverse: \n");
s_reverse(n);
printf("%s\n", n);
printf("Palindrom? (0 = nein, 1 = ja): \n");
s_reverse(n);
printf("%d\n", isPalindropme(n));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment