others - 在C中,字母順序如何從Z移動到A?

135 4


#include <cs50.h>


#include <stdio.h>


#include <string.h>


#include <ctype.h>


#include <stdlib.h>



int main(int argc, string argv[])


{ 


 int counter = 0; 


 if (argc == 2)


 {


 for (int k = 0; k <strlen(argv[1]); k++)


 {


 if (isdigit(argv[1][k]))


 {


 counter++; 


 }


 }



 if (strlen(argv[1]) == counter) 


 {


 string s = get_string("plaintext:"); 


 printf("ciphertext:");


 for (int j = 0; j < strlen(s); j++) 


 {


 int c = (int) s[j]; 


 printf("%c", c + atoi(argv[1]));


 }


 printf("n");


 } 


 else


 {


 printf("Usage: ./caesar keyn");


 }


 }


 else 


 {


 printf("Usage: ./caesar keyn");


 } 


}



时间: 原作者:

53 1

我希望數字一旦超過閾值(就像時鐘)就回到起始位置,我會發現模數是最好的解決方案。

例如:


int hour = 11;


hour = (hour + SOME_VALUE) % 12; // This will ensure hour is always a value between 0 and 11



原作者:
...