ricod1996

palindromes_old.c

Dec 10th, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. void drehen(char wort[100], int laenge)
  5. {
  6.     char trow[100];
  7.     char *head;
  8.     char *back;
  9.     int i,j=0;
  10.     int counter = 0;
  11.     int test;
  12.     for (i = laenge; 0<=i; i--)
  13.     {
  14.         trow[j] = wort[i];
  15.         j = j + 1;
  16.     }
  17.     for (i = 0; i <= laenge; i++)
  18.     {
  19.         putchar(trow[i]);
  20.     }
  21.     printf("\n\n");
  22.     test = i / 2;
  23.     head = &wort[0];
  24.     back = &trow[0];
  25.     back = back + 1;
  26.     i = 0;
  27.     while (i!=test)
  28.     {
  29.         if (*head == *back)
  30.             counter = counter + 1;
  31.         head = head + 1;
  32.         back = back + 1;
  33.         i=i + 1;
  34.     }
  35.     counter = (counter *2)+1;
  36.     if (counter >= laenge)
  37.         printf("Das Wort ist ein Palidrom!\n");
  38.     else
  39.         printf("Das Wort ist kein Palidrom!\n");
  40. }
  41. void convertieren(char *pchar)
  42. {
  43.     while (*pchar != '\n')
  44.     {
  45.         if (*pchar >= 65 && *pchar<=90)
  46.              *pchar = *pchar + 32;
  47.         pchar = pchar + 1;
  48.     }
  49. }
  50. int main(void)
  51. {
  52.     char *pchar;
  53.     int i = 0;
  54.     FILE*datei;
  55.     char wort[100];
  56.     fopen_s(&datei,"Text.txt","r");
  57.     fread(wort, sizeof(double), 100, datei);
  58.     fgets(wort, 100, datei);
  59.     fclose(datei);
  60.     while (wort[i] != EOF)
  61.     {
  62.         putchar(wort[i]);
  63.         i = i + 1;
  64.     }
  65.     pchar = wort;
  66.     convertieren(pchar);
  67.     drehen(wort, i);
  68.    
  69.     printf("\n");
  70.     system("pause");
  71.     return EXIT_SUCCESS;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment