others - 在C中,字母顺序如何从Z移动到A?


#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");


 } 


}



时间: 作者:

我希望数字一旦超过阈值(就像时钟)就回到起始位置,我会发现模数是最好的解决方案。

例如:


int hour = 11;


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



作者:
...