Skip to main content
code hidden per academic honesty guidelines.
Source Link
curiouskiwi
  • 18.7k
  • 2
  • 18
  • 43

I'm working on pset2, Caesar's cipher part. I understand how to proceed to do the encryption and my program compile well. The first line of command allow the user to correctly enter his key. After the first return, user can write some plaintext to encrypt, and then, there appear the problem. My program get block to the "GetString()" command line and ask continually to enter strings...

May someone can help me to solve this problem?!

Thanks for your answer and your time.

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

int main(int argc, string argv[])
{
    if (argc != 2) 
    {
        printf("Usage : ./asciimath key\n");
        return 1;
    }
    
    int key = atoi(argv[1]);

    string plaintext = GetString();
    int length = strlen(plaintext), i = 0;
    char cipher[length];

    while (i < length) 
    {
        if (isalpha(plaintext[i])) 
        {
            if (isupper(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 65;
                i++;
            }
                               
            if (islower(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 97;
                i++;
            }          
            else return 1;
        }
            
            if (isalpha(plaintext[i])) 
            {
                cipher[i] = plaintext[i];
                i++;
            }
        }
    printf("%s\n", cipher);
    return 1;
}   

[code hidden behind edit flag]

I'm working on pset2, Caesar's cipher part. I understand how to proceed to do the encryption and my program compile well. The first line of command allow the user to correctly enter his key. After the first return, user can write some plaintext to encrypt, and then, there appear the problem. My program get block to the "GetString()" command line and ask continually to enter strings...

May someone can help me to solve this problem?!

Thanks for your answer and your time.

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

int main(int argc, string argv[])
{
    if (argc != 2) 
    {
        printf("Usage : ./asciimath key\n");
        return 1;
    }
    
    int key = atoi(argv[1]);

    string plaintext = GetString();
    int length = strlen(plaintext), i = 0;
    char cipher[length];

    while (i < length) 
    {
        if (isalpha(plaintext[i])) 
        {
            if (isupper(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 65;
                i++;
            }
                               
            if (islower(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 97;
                i++;
            }          
            else return 1;
        }
            
            if (isalpha(plaintext[i])) 
            {
                cipher[i] = plaintext[i];
                i++;
            }
        }
    printf("%s\n", cipher);
    return 1;
}   

I'm working on pset2, Caesar's cipher part. I understand how to proceed to do the encryption and my program compile well. The first line of command allow the user to correctly enter his key. After the first return, user can write some plaintext to encrypt, and then, there appear the problem. My program get block to the "GetString()" command line and ask continually to enter strings...

May someone can help me to solve this problem?!

Thanks for your answer and your time.

[code hidden behind edit flag]

deleted 4 characters in body
Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

I'm working on pset2, Caesar's cipher part. I understand how to proceed to do the encryption and my program compile well. The first line of command allow the user to correctly enter his key. After the first return, user can write some plaintext to encrypt, and then, there appear the problem. My program get block to the "GetString()" command line and ask continually to enter strings...

May someone can help me to solve this problem?!

Thanks for your answer and your time.

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

int main(int argc, string argv[])
{
    if (argc != 2) 
    {
        printf("Usage : ./asciimath key\n");
        return 1;
    }
    
    int key = atoi(argv[1]);

    string plaintext = GetString();
    int length = strlen(plaintext), i = 0;
    char cipher[length];

    while (i < length) 
    {
        if (isalpha(plaintext[i])) 
        {
            if (isupper(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 65;
                i++;
            }
                               
            if (islower(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 97;
                i++;
            }          
            else return 1;
            }
            
            if (isalpha(plaintext[i])) 
            {
                cipher[i] = plaintext[i];
                i++;
            }
        }
    printf("%s\n", cipher);
    return 1;
}   

I'm working on pset2, Caesar's cipher part. I understand how to proceed to do the encryption and my program compile well. The first line of command allow the user to correctly enter his key. After the first return, user can write some plaintext to encrypt, and then, there appear the problem. My program get block to the "GetString()" command line and ask continually to enter strings...

May someone can help me to solve this problem?!

Thanks for your answer and your time.

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

int main(int argc, string argv[])
{
    if (argc != 2) 
    {
        printf("Usage : ./asciimath key\n");
        return 1;
    }
    
    int key = atoi(argv[1]);

    string plaintext = GetString();
    int length = strlen(plaintext), i = 0;
    char cipher[length];

    while (i < length) 
    {
        if (isalpha(plaintext[i])) 
        {
            if (isupper(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 65;
                i++;
            }
                               
            if (islower(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 97;
                i++;
            }          
            else return 1;
            }
            
            if (isalpha(plaintext[i])) 
            {
                cipher[i] = plaintext[i];
                i++;
            }
        }
    printf("%s\n", cipher);
    return 1;
}   

I'm working on pset2, Caesar's cipher part. I understand how to proceed to do the encryption and my program compile well. The first line of command allow the user to correctly enter his key. After the first return, user can write some plaintext to encrypt, and then, there appear the problem. My program get block to the "GetString()" command line and ask continually to enter strings...

May someone can help me to solve this problem?!

Thanks for your answer and your time.

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

int main(int argc, string argv[])
{
    if (argc != 2) 
    {
        printf("Usage : ./asciimath key\n");
        return 1;
    }
    
    int key = atoi(argv[1]);

    string plaintext = GetString();
    int length = strlen(plaintext), i = 0;
    char cipher[length];

    while (i < length) 
    {
        if (isalpha(plaintext[i])) 
        {
            if (isupper(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 65;
                i++;
            }
                               
            if (islower(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 97;
                i++;
            }          
            else return 1;
        }
            
            if (isalpha(plaintext[i])) 
            {
                cipher[i] = plaintext[i];
                i++;
            }
        }
    printf("%s\n", cipher);
    return 1;
}   
improved formatting -please use style50 to assess code formatting
Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

#include <stdio.h>

#include <stdlib.h>

#include <cs50.h>

#include <string.h>

#include <ctype.h>

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

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

int main(int argc, string argv[])
{
    if (argc != 2) {
    {
        printf("Usage : ./asciimath key\n");
 
        return 1;
 
    }

int key = atoi(argv[1]);

    
    int key = atoi(argv[1]);

    string plaintext = GetString();
 
    int length = strlen(plaintext), i = 0;
 
    char cipher[length];

 

    while (i < length) {


    {
        if (isalpha(plaintext[i])) {


        {
            if (isupper(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 65;
 
                i++;
            }
                }


               
            if (islower(plaintext[i])) {
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 97;
 
                i++;
 
            }    }


       
  
           else return 1;
 
            }
 
            
            if (isalpha(plaintext[i])) {
            {
                cipher[i] = plaintext[i];
 
                i++;
 
            }
 
        }

printf("%s\n", cipher);

    printf("%s\n", cipher);
    return 1;
}   

}

#include <stdio.h>

#include <stdlib.h>

#include <cs50.h>

#include <string.h>

#include <ctype.h>

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

if (argc != 2) {

    printf("Usage : ./asciimath key\n");
 
    return 1;
 
}

int key = atoi(argv[1]);

string plaintext = GetString();
 
int length = strlen(plaintext), i = 0;
 
char cipher[length];

 

while (i < length) {



    if (isalpha(plaintext[i])) {


    
        if (isupper(plaintext[i])) {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 65;
 
                i++;

                }


        
if (islower(plaintext[i])) {

                cipher[i] = ((int)plaintext[i] + key) % 26 + 97;
 
                i++;
 
                }


        
         else return 1;
 
        }
 

        if (isalpha(plaintext[i])) {

            cipher[i] = plaintext[i];
 
            i++;
 
        }
 
    }

printf("%s\n", cipher);

return 1;

}

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

int main(int argc, string argv[])
{
    if (argc != 2) 
    {
        printf("Usage : ./asciimath key\n");
        return 1;
    }
    
    int key = atoi(argv[1]);

    string plaintext = GetString();
    int length = strlen(plaintext), i = 0;
    char cipher[length];

    while (i < length) 
    {
        if (isalpha(plaintext[i])) 
        {
            if (isupper(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 65;
                i++;
            }
                               
            if (islower(plaintext[i])) 
            {
                cipher[i] = ((int)plaintext[i] + key) % 26 + 97;
                i++;
            }           
            else return 1;
            }
            
            if (isalpha(plaintext[i])) 
            {
                cipher[i] = plaintext[i];
                i++;
            }
        }
    printf("%s\n", cipher);
    return 1;
}   
Source Link
Loading