I need help. Does anyone knows how to fix this? I've tried debugging and the problem is that the int k is always seems to be 0 but I don't really understand why :( $

int main (int argc, string argv[]) {

if ( argc != 2 ){
    printf("Usage : ./vinegere <key> \n");
    return 1;

    for(int z = 0; z < strlen(argv[1]); z++){
        printf("Only alpahabetic key is allowed :)/n");
        return -1;

 printf("Your message: ");
    string t = GetString();

for(int i = 0; i < strlen(argv[1]); i++){ //getting key
    int k = atoi(argv[1][i]);

    for (int j = 0, n = strlen(t); j < n;j++){ // getting text converted

                int a = (( t[j] -65 + k)% 26) + 65;
                printf("%c",a );

                int a = (( t[j]-97 + k)% 26)+97;

            printf("%c", t[j]);




The fact that k always seems to be 0 is a clue. According to the documentation for atoi(), it will return 0 when the given parameter (in this case, argv[1][i]) is not convertible to a number.

The function atoi() is used to convert a string representation (i.e., a string of numeric characters) of an integer to an actual integer which it will then return. It will not work on alpha characters.

If you review the class material, you will find that a char can be treated as a one byte signed integer, so there's no need to do this.

There are other issues in your code, but they aren't part of your question. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .