i have a problem with this pset. My program compiles properly, but when i'm launching it with key, it stops before get_string... When i'm using the only_digits function which is commented in bottom of this file it runs well, program is getting string and making cipher, but check50 tells me that: handles non-numeric key timed out while waiting for program to exit
I dont know how to make it running properly, can you help me?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, string argv[])
{
if (argc != 2)
{
printf("Usage: ./caesar key\n");
return 1;
}
int length = strlen(argv[1]);
for (int j = 0; j <= length; j++)
{
if (isdigit(argv[1][j]) != 0)
{
printf("Success\n");
return 0;
}
else
{
printf("Usage: ./caesar key\n");
return 1;
}
}
int key = atoi(argv[1]);
if (key < 0)
{
printf("Usage: ./caesar key\n");
return 1;
}
string plaintext = get_string("plaintext : ");
int plain = strlen(plaintext);
char c[plain];
for (int i = 0; i <= plain; i++)
{
if (isalpha(plaintext[i]) && isupper(plaintext[i]))
{
c[i] = ((((plaintext[i] + key % 26) - 'A') % 26) + 'A');
}
else if (isalpha(plaintext[i]) && islower(plaintext[i]))
{
c[i] = ((((plaintext[i] + key % 26) - 'a') % 26) + 'a');
}
else
{
c[i] = (plaintext[i]);
}
}
printf("ciphertext: %s\n", c);
}
// string only_digits(string s) {
// int length = strlen(s);
// for (int j = 0; j <= length; j++)
// {
// if (isdigit(s[j]) == 0)
// {
// return 0;
// }
// else
// {
// printf("Usage: ./caesar key\n");
// break;
// }
// }
// return s;
// }
{}
icon in the format bar.