3 votes

Pset2 - Receiving different outputs each time I run my code- Vigenere.c

When encrypt[n] is declared, it doesn't allow for the end of string marker at the end. Also, the end of string marker is never added to the string, so when it is printed at the end of the program, ...
user avatar
  • 64.2k
2 votes
Accepted

vigenere.c unknown problem / am I an idiot?

It's not so much being an idiot as it is having tunnel vision. ;-) The problem isn't about vigKey. It's about what was done with the key string. If you look carefully at what the working code does, ...
user avatar
  • 64.2k
1 vote
Accepted

In pset2, Vigenere, I made and used an array that I would like for it to be explained

The detail you seem to miss is that a char array is not a string unless it ends in the NUL char '\0' If you have char text[] = "Foobar";, that is stored {'F', 'o', 'o', 'b', 'a', 'r', '\0'} ...
user avatar
  • 18.4k
1 vote
Accepted

I have multiple issues with my code

Let's start here: if (argc != 2 && !isalpha(argv[1])) BOTH conditions have to be met for the usage statement to be printed. The problem is that if either condition is met, it should ...
user avatar
  • 64.2k
1 vote
Accepted

Vigenère spitting out random strings

There are a number of issues in the code that are impacting it. First, look at this: int *keyInt = malloc(strlen(key)); This allocates n bytes where n is the number of chars in the key string. ...
user avatar
  • 64.2k
1 vote

CS50 pset2 vigenere problem getting the shift

When do you want this printf("%c", text[i]); to execute? When does it actually execute? Spoiler: once for every char in text. That explains the "doubling". I will also warn that this key_val = key[i%...
user avatar
1 vote

Problem about vigenere.c

Maybe it gets clearer if you use 'A' instead of 65 (char is a kind of integer, so 'A' is an 8-bit integer of value 65). In case of a lowercase letter, subtract 'a' (or 97) instead of 'A' (or 65). And ...
user avatar
  • 20.7k
1 vote

Vigenere.c has some problem in accepting alpabetic as a key

Look at where and how k is declared. During each pass through the for loop, k is declared as starting at argv[i]. That means that on the first pass, k=argv[0], the name of the program. This sneaks ...
user avatar
  • 64.2k
1 vote
Accepted

not satisfying the condition for input

The code is actually testing for non-alpha keys. The problem is that it is prompting for the plaintext before checking the key. It's a sequence issue. As a side issue, consider how you might make the ...
user avatar
  • 64.2k
1 vote
Accepted

Pset3 help : vigenere error

atoi takes a string as argument. You are passing it a single char. As an example, if you have atoi("123"); you'll get 123. But you can't pass it atoi('1') as that is a char. If you are trying to ...
user avatar
  • 18.4k
1 vote
Accepted

Vigenere can't get correct output from key

I really don't know where your numbers start and end, and what they refer to (I don't think that's the output of the code you show), at least some whitespace between would have been nice. Also, the ...
user avatar
  • 20.7k
1 vote
Accepted

vigenere and space character

Any non-letter should be returned as-is, not changed at all. Note that copying a non-letter won't affect your position inside the keyword! plaintext: Meet me at the park at eleven am effective ...
user avatar
  • 20.7k
1 vote
Accepted

Pset2 Vigenere very close but errors on Check50

The index inside the keyword should be incremented only when encrypting a letter. It has to be kept separate from the index in the plaintext, which advances on any character. Case of character to be ...
user avatar
  • 20.7k
1 vote

Please correct my mistakes in my vigenere code

Don't be scared by the number of errors, fixing them one by one quickly reduces the number. If you are unsure about how to use a feature, search it in the CS50 reference or on the internet. It's ...
user avatar
  • 20.7k
1 vote
Accepted

Pset2 vigenere key verification problems

isalpha() takes a single character as a parameter. You are trying to shove an entire string down its throat, so it chokes on it and gives you back a seg fault. If you want to check the string, you ...
user avatar
  • 64.2k
1 vote
Accepted

Vigenere compiles but doesn't ask for input?

I see a problem here. After you type condition and it is more than one line you need those brackets: if (!isalpha(argv[1][i])) { printf("Please enter ...\n"); return 1; } ...
user avatar
1 vote
Accepted

Pset2 Vigenere Cipher error

printf("%c", ((((text[j] - 65) + key[p]%strlen(key))% 26) + 65)); The problem arises because of how strlen() was used here. strlen() returns a value of type size_t, which is actually an unsigned long....
user avatar
  • 64.2k
1 vote
Accepted

bad access error or segmentation fault on Vigenere

I'm not entirely sure, but I'm thinking that your problem lies here: if (c > kl - 1) { key[c] = (key[c % kl]); } This attempts to do an assignment to an element in key[]. Let's say that kl=5 and ...
user avatar
  • 64.2k
1 vote
Accepted

pset2. need help on vigenere.c code

I suspect that you are encoding characters, but incorrectly. That's because you are selecting the wrong char from the key to encode. Try working through the code with paper and pencil and sample data ...
user avatar
  • 64.2k
1 vote
Accepted

Why is my Vigenere cypher not processing my keyword correctly?

int x = (argv[1][j])-'0'; looks like your problem. You are subtracting the ascii value of the 0 symbol from the character in argv[1][j]. In effect, you have done int x = (argv[1][j])-48; I don't ...
user avatar
  • 64.2k
1 vote
Accepted

Vigenere code has Segmentation error

Your segmentation fault is due to the following line: if(isalpha(argv[1]))//checks if key is letters isalpha() tests to see if a single character is an alpha. It does not operate on whole strings. ...
user avatar
  • 64.2k

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