I was doing the problem set2 for cs50x course, and while solving the caesar problem, i came across some unsual ouputs

    #include<stdio.h>
    #include<cs50.h>
    #include<ctype.h>
    #include<string.h>

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

        if(argc==2)  //to make sure there's only one string after ./caesar
        {
        int digit=0,key=0;

            for(int i=0,n=strlen(argv[1]);i<n;i++)
            {
                if(argv[1][i]>='0' && argv[1][i]<='9')
                {
                digit= argv[1][i]-'0';
                key=key*10+digit;
                }

                else{
                    printf("Usage: ./caesar keyn");
                    return 1;
                }

        }

        string text=get_string("plainttext:  ");
        printf("ciphertext: ");


        key=key%26;

        for(int i=0,n=strlen(text);i<n;i++){

            if(islower(text[i]))
            {

            text[i]=text[i]+key;

                if(text[i]>'Z')
                {
                    text[i]=text[i]-26;
                }


                printf("%c",(char)text[i]);




            }

        else if(isupper(text[i]))
            {
                text[i]=text[i]+key;

                if(text[i]>'Z')
                {
                    text[i]=text[i]-26;
                }


                printf("%c",(char)text[i]);
            }

            else
            printf("%c",(char)text[i]);


        }

        printf("n %i",key);




        return 0;

        }







    else{
            printf("Usage: ./caesar keyn");
            return 1;
        }
    }

Design and implement a program, caesar, that encrypts messages using Caesar’s cipher.

  • Implement your program in a file called caesar.c in a directory called caesar.
  • Your program must accept a single command-line argument, a non-negative integer. Let’s call it
  • for the sake of discussion.
  • If your program is executed without any command-line arguments or with more than one command-line argument, your program should print an error message of your choice (with printf) and return from main a value of 1 (which tends to signify an error) immediately.
  • If any of the characters of the command-line argument is not a decimal digit, your program should print the message Usage: ./caesar key and return from main a value of 1.
  • Do not assume that
  • will be less than or equal to 26. Your program should work for all non-negative integral values of
  • less than
  • In other words, you don’t need to worry if your program eventually breaks if the user chooses a value for
  • that’s too big or almost too big to fit in an int. (Recall that an int can overflow.) But, even if
  • is greater than
  • alphabetical characters in your program’s input should remain alphabetical characters in your program’s output. For instance, if
  • is
  • A should not become even though is
  • positions away from A in ASCII, per asciitable.com; A should become B, since B is
  • positions away from A, provided you wrap around from Z to A.
  • Your program must output plaintext: (with two spaces but without a newline) and then prompt the user for a string of plaintext (using get_string).
  • Your program must output ciphertext: (with one space but without a newline) followed by the plaintext’s corresponding ciphertext, with each alphabetical character in the plaintext “rotated” by k positions; non-alphabetical characters should be outputted unchanged.
  • Your program must preserve case: capitalized letters, though rotated, must remain capitalized letters; lowercase letters, though rotated, must remain lowercase letters.
  • After outputting ciphertext, you should print a newline. Your program should then exit by returning 0 from main.

https://cs50.harvard.edu/x/2024/psets/2/caesar/

this is the link to the problem

basically when I try “world, say hello” as my plaintext and 12 as key it doesn’t act like it should, it gives out random output for w and y. like weird question marks in place of it`

New contributor

persiandrunkard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật