Advertisement
Guest User

geocache.c

a guest
Jan 13th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. /* Philipp Sosna Sudiengruppe 1A Parktikumsgruppe II
  2.  
  3. Lerngruppe: Tim Zaska, Philipp Sosna, Christane Sagan
  4.  
  5. Programm für Geocache
  6.  
  7. */
  8.  
  9. // compiler params: -std=g99
  10.  
  11. #include <stdio.h>
  12.  
  13. int main () {
  14.  
  15.     char text[99];
  16.     int laenge = 0; // leerzeichen
  17.     int ASCIIwert;
  18.  
  19.     printf("Geben Sie einen Text ein:\n");
  20.     gets(text);    // lass das leerzeichen zwischen gets (text) weg
  21.  
  22.     laenge = strlen(text);
  23.  
  24.     if(laenge >= sizeof(text)) // anstatt >= 100 nimmst du hier am besten die definierte Arraylänge, dann muss man es nicht jedes mal ändern, das ist wichtig wenn du mehrere arrays hast
  25.     {
  26.         printf("ERROR zuviele Zeichen!\n");     // um ein Tab rein verschieben sieht besser aus
  27.         return 0;   // lass da die leerzeile weg
  28.     }
  29.  
  30.     printf("\n\nCache:\t");
  31.  
  32.     for(int i = 0; i < laenge; i++)   // nimm for anstatt while (du musst dem compiler angeben, dass du mit -std=g99 arbeitesr)
  33.     {
  34.         ASCIIwert = (int) text[i]; // leerzeichen zwischen ASCIIwert und dem =
  35.  
  36.         if(ASCIIwert >= 65 && ASCIIwert <= 77 || ASCIIwert >= 97 && ASCIIwert <= 109)
  37.         {
  38.             ASCIIwert += 13;    // nimm += anstatt ASCIIwert = ASCIIwert+13
  39.             text[i] = (char) ASCIIwert;
  40.         }// spar dir die leerzeilen, if ist in der c Schreibform eh so platzfressend
  41.         else if(ASCIIwert >= 78 && ASCIIwert <= 90 || ASCIIwert >= 110 && ASCIIwert <= 122)
  42.         {
  43.             ASCIIwert -= 13;
  44.             text[i] = (char) ASCIIwert;
  45.         }
  46.  
  47.         printf("%c", text[i]);
  48.         // else ist unnötig, nimm einfach einmal ein printf, ist eh immer das selbe ^^
  49.     }
  50.     printf("\n");   // brauchst du eig nicht zwingend
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement