3
votes
Accepted
GetString() giving me a segfault in C
The description of the GetString() function clearly states that it can return NULL on an error or an EOF.
If you pass the return value to strlen() without checking, your program will crash.
string s ...
2
votes
Accepted
length of argv always change to 1?
Actually, it's not always changing to 1 on the last line. The result is always dependent on the input to argv[1]. Specifically, the last number printed depends on where the first 'a' appears in the ...
1
vote
Accepted
Readability CS50 Not counting the spaces
string input = get_string("Text:"); //getting input from the user
int len = strlen(input); //determining the length of the string
int space = 0; //declaring a variable to count whitespaces
...
1
vote
Strlen function does not give the intended output
From man scanf (conversions):
s
Matches a sequence of non-white-space characters; the next pointer
must be a pointer to character array that is long enough to hold the
input sequence and ...
1
vote
Accepted
For loop stops when pulling chars from string (vigenere)
You've hit on the cause, so bonus points for debugging it enough to isolate the issue! Now the explanation. Look at the for loop:
for (int j = 0; j < strlen(k); j++)
On each pass, it calculates ...
1
vote
Accepted
Pset2 - Vigenere - Encypts all variations of "barfoo" as "ca\..." (no case issues)
The problem lies in the last for loop. The for loop is controlled by strlen(pt), which is recalculated on every loop iteration. Inside the loop, the ASCII values of the letters in pt are converted to ...
1
vote
pset 2 initials: trouble printing only first char and char after space
You should print uppercased name[0] if it's not a space and is either the first character or following a space.
If it's the first character, there's no previous element, but conveniently, the || ...
1
vote
pset2 vigenere cipher - Why did the program return the wrong output
The problem lies in your for loop that converts the key from letters to numbers. It's a very subtle problem. Look at the for loop setup:
for(int n=0; n < strlen(key); n++)
The loop is going to ...
1
vote
Accepted
Got an expected expression error on strlen ( values[] )
values[] is an array with strings in it, you need to index it to measure the length of the string in it.
And you really shouldn´t declare "n" as a variable for your for-loop, name it old-fashioned "i"...
1
vote
GetString() giving me a segfault in C
Two things.
One. Not sure why you say "not in the CS50 library" when you then pasted in the exact function that is in the CS50 library.
Two. You'd generally get a segfault with strlen if the string ...
Only top scored, non community-wiki answers of a minimum length are eligible