Ich versuche, eine Funktion, die eine Zeichenfolge und eine Zahl und wenn die Zahl größer ist die '0', so wird es die Caesar-Chiffre mit der Zeichenfolge und der Zahl, die der Benutzer trat ein. zum Beispiel -> 'Stack' und die Nummer ist '3' -> 'uvdfn'. Wenn die Zahl '0' ist, wird die Zeichenfolge umgekehrt. zum Beispiel - 'Stack' -> 'KCATS'Caesar Chiffre und Reverse-Text-Programm
Ich weiß nicht, was ist das Problem mit dem Code, ich sehe nichts falsch.
/*********************************
* Class: MAGSHIMIM C2 \t \t \t *
* Week 3 *
**********************************
* Thank you for Ofek and Dor for *
* Editing this template :) *
**********************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void decryptText(char* encText, int n);
#define STR_SIZE 50
int main(void)
{
\t char str[STR_SIZE];
\t int num = 0;
\t printf("Please enter the string : ");
\t fgets(str, STR_SIZE, stdin);
\t printf("Please enter a number : ");
\t scanf("%d", &num);
\t decryptText(str, num);
system("PAUSE");
\t return 0;
}
void decryptText(char* encText, int n)
{
\t int i = 0;
\t int j = 0;
\t char temp = 0;
\t int strLen = strlen(encText);
\t if (n > 0)
\t {
\t \t for (i = 0; i < strLen; i++)
\t \t {
\t \t \t if (*(encText + i) == ' ') { }
\t \t \t else
\t \t \t {
\t \t \t \t if (*(encText + i) >= 'x')
\t \t \t \t {
\t \t \t \t \t *(encText + i) = (*(encText + i)) - 26;
\t \t \t \t }
\t \t \t \t *(encText + i) = (*(encText + i)) + n;
\t \t \t }
\t \t }
\t \t printf("The array after the program deciphered it : \n");
\t \t printf("%s", encText);
\t }
\t else if (n == 0)
\t {
\t \t for (i = 0; i < strLen; i++)
\t \t {
\t \t \t for (j = 0; j >= 0; j--)
\t \t \t {
\t \t \t \t temp = *(encText + i);
\t \t \t \t *(encText + i) = *(encText + j);
\t \t \t \t *(encText + i) = temp;
\t \t \t }
\t \t }
\t \t printf("The array after the program cracked it : \n");
\t \t printf("%s", encText);
\t }
}