Hot answers tagged

6

GAR, figured it out. I didn't take the details of "your program should yell at you" literally. This works now. if (argc != 2) { printf("YOU SCREWED UP!"); return 1; }


1

Figured it out. update50 and restart.


1

Your issue is that you are only using the first letter of the key. int k = shift (key[0]); You need to use each subsequent letter as you move along ciphering the plaintext. That is the challenge with vigenere versus caesar.


1

I assume the % strlen(key) is causing some type conversion. Your logic is wrong. First iterate the key to ensure all characters are alphabetic, and maybe also uppercase the key there if you want. Then, after the first loop, iterate the plaintext, keeping a separate index for the key that you increment on encrypting a letter only. Separate loops. toupper(key[...


1

Instead of printing non-alphas without encoding them, this code is printing the next encoded letter for each preceeding non-alpha. In other words, if the key was a (meaning don't encode, just echo everything), and the string was b12c . de it would print bcccdddde. While I've never seen this effect, the problem is a common one. The index for the key, j, is ...


1

Your instincts are more or less correct. You have actually declared key twice, once as a global and a second time as a local var inside main(). Specifically, the line int key = atoi(argv[1]); is the second declaration and it takes precedence over the global var, so any usage of key inside of main will use the local version. The actual error is that once ...


1

The best and most efficient way is to out grow CS50.h use char* newString = argv[1]; argv will always be there so you might as well point to it or use it.


1

string keyword = argv[1]; will work because you are assigning the address of string argv[1] to keyword. You can now treat keyword as a char array and access the individual characters as keyword[i]. You could also do this: char keyword[strlen(argv[1])+1]; strcpy(keyword, argv[1]); Instead of keyword pointing at the same memory location as argv[1], this ...


1

I had the same error until I moved my declared variables AFTER the if... if (argc !=2) { printf("Oops! Only 2 arguments allowed"); return 1; } int k = atoi(argv[1]); string p;


Only top voted, non community-wiki answers of a minimum length are eligible