i'm having these errors when i check my code. This is it:
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
int main(int argv, string argc[]) {
int count = 0;
for (int i = 0; i < 26; i++){
if ((argc[1][i] < 'A' || argc[1][i] > 'Z') && (argc[1][i] < 'a' || argc[1][i] > 'z')){
count = count + 1;
}
}
if ((argv != 2) || (count > 0)){
printf("Usage: ./substitution key\n");
return 1;
}
else if (strlen(argc[1]) != 26){
printf("Key must contain 26 characters.\n");
return 1;
}
else {
string plain = get_string("plaintext: ");
int sub[26];
for (int j = 0; j < 26; j++){
if (argc[1][j] >= 'a' && argc[1][j] <= 'z'){
sub[j] = argc[1][j];
}
else if (argc[1][j] >= 'A' && argc[1][j] <= 'Z'){
sub[j] = argc[1][j];
}
}
string outro[1][strlen(plain)];
for (int k = 0; k < strlen(plain); k++){
char cypher;
if (plain[k] >= 'a' && plain[k] <= 'z'){
cypher = sub[(int) plain[k] - 97];
(char) outro[0][k] = (char) tolower(cypher);
}
else if (plain[k] >= 'A' && plain[k] <= 'Z'){
cypher = sub[(int) plain[k] - 65];
(char) outro[0][k] = (char) toupper(cypher);
}
else {
(char) outro[0][k] = (char) plain[k];
}
if (k == (strlen(plain) - 1)){
string output = (string) outro[0];
printf("ciphertext: %s\n", output);
}
}return 0;
}
}
Here's the error log:
:) substitution.c exists
Log
checking that substitution.c exists...
:) substitution.c compiles
Log
running clang substitution.c -o substitution -std=c11 -ggdb -lm -lcs50...
:( encrypts "A" as "Z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key
output not valid ASCII text
Log
running ./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA...
sending input A...
checking for output "ciphertext: Z\n"...
:( encrypts "a" as "z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key
output not valid ASCII text
Log
running ./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA...
sending input a...
checking for output "ciphertext: z\n"...
:( encrypts "ABC" as "NJQ" using NJQSUYBRXMOPFTHZVAWCGILKED as key
output not valid ASCII text
Log
running ./substitution NJQSUYBRXMOPFTHZVAWCGILKED...
sending input ABC...
checking for output "ciphertext: NJQ\n"...
:( encrypts "XyZ" as "KeD" using NJQSUYBRXMOPFTHZVAWCGILKED as key
output not valid ASCII text
Log
running ./substitution NJQSUYBRXMOPFTHZVAWCGILKED...
sending input XyZ...
checking for output "ciphertext: KeD\n"...
:) encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZTEOGXHCIPJSQD as key
Log
running ./substitution YUKFRNLBAVMWZTEOGXHCIPJSQD...
sending input This is CS50...
checking for output "ciphertext: Cbah ah KH50\n"...
checking that program exited with status 0...
:) encrypts "This is CS50" as "Cbah ah KH50" using yukfrnlbavmwzteogxhcipjsqd as key
Log
running ./substitution yukfrnlbavmwzteogxhcipjsqd...
sending input This is CS50...
checking for output "ciphertext: Cbah ah KH50\n"...
checking that program exited with status 0...
:) encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZteogxhcipjsqd as key
Log
running ./substitution YUKFRNLBAVMWZteogxhcipjsqd...
sending input This is CS50...
checking for output "ciphertext: Cbah ah KH50\n"...
checking that program exited with status 0...
:) encrypts all alphabetic characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key
Log
running ./substitution DWUSXNPQKEGCZFJBTLYROHIAVM...
sending input The quick brown fox jumps over the lazy dog...
checking for output "ciphertext: Rqx tokug wljif nja eozby jhxl rqx cdmv sjp\n"...
checking that program exited with status 0...
:( handles lack of key
failed to execute program due to segmentation fault
Log
running ./substitution...
:) handles invalid key length
Log
running ./substitution QTXDGMKIPV...
checking that program exited with status 1...
:) handles invalid characters in key
Log
running ./substitution ZWGKPMJRYISHFEXQON2DLUACVT...
checking that program exited with status 1...
:( handles duplicate characters in key
timed out while waiting for program to exit
Log
running ./substitution YFDTSMPBVIERGHEWONUAKLQXCZ...
:( handles multiple duplicate characters in key
timed out while waiting for program to exit
Log
running ./substitution BBCCEFGHIJKLMNOPQRSTUVWXYZ...
Can anyone please help me find my (main) errors? At the end i created a string variable and assigned the values of the outro[] array thinking that the error was that it lacked "\0", but that wasn't the problem ( i think). When i run it myself with their values, it appear to be working just fine.
Thanks in advance!