Hot answers tagged

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 ...
  • 64.7k
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"...
  • 36
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 ...
  • 64.7k
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 ...
  • 64.7k
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 || ...
  • 20.7k
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 ...
  • 64.7k

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