Questions tagged [pset2]

The problem set for Week 2 continues with the C programming language used in problem set 1.

Filter by
Sorted by
Tagged with
0 votes
1 answer
163 views

Pset2 Readability. I am starting to do readbility and for some reason the code i wrote this far seems not to be compiling properly

My for loop doesn't seem to be executing. When i run the program it seems for loop is been skipped. Can someone please help me out. #include <stdio.h> #include <cs50.h> #include <string....
user avatar
2 votes
0 answers
565 views

CS50 - PSET2 - Substitution Segmentation fault

I keep getting 'Segmentation fault' every time I run the code(mentioned below). The code is compiling just fine. It's asking for input and is returning required message when the command line argument ...
user avatar
  • 23
0 votes
1 answer
389 views

Caesar Pset2 Handles non-numeric key :(

I am tearing my hair out on this exercise. I cannot get it to pass a non-numeric key. I've played around with the code for 2 weeks now. I can either get it to handle a numeric key or handle a lack of ...
user avatar
0 votes
0 answers
96 views

CS50x pset2 substitution, check50 test returns negative even though output is correct

My code fails only one of the test in check50 even though the output is correct and passes other ones. The test it fails: :( encrypts all alphabetic characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key ...
user avatar
  • 1
0 votes
1 answer
176 views

PSET2 Readability - tests no passing

I am not sure what I am doing wrong. #include <stdio.h> #include <cs50.h> #include <ctype.h> #include <string.h> #include <math.h> int main(void) { //Create integers ...
user avatar
0 votes
1 answer
30 views

pset2 making a whole string uppercase for use in substitution.c

I am trying to use the following helper function inside my substitution.c script: string upper(string key) { int n = strlen(key); char key_upper[n]; for (int i = 0; i < n; i++) { ...
user avatar
0 votes
2 answers
58 views

Why the if statements don't work when I put them into loops? Caesar PSET2

Help, please. The program works fine until I want to add the loops and when I do that the if statements inside it won't work and it will just ask for the key and will output the same text as the input ...
user avatar
  • 1
0 votes
1 answer
83 views

Pset2 Coleman-Lau Index Always Prints -15

I'm struggling with PSet 2 Readability. I don't want to cheat the answers because I am genuinely trying to learn how to think better and improve my logic. I so far have been able to get the letter ...
user avatar
0 votes
2 answers
74 views

pset 2 caesar -- bug that specifically lowercase letters with key more than 52 don't work -- everything else does

// ciphering for (int i = 0, n = strlen(plaintext); i < n; i++) { ... // lowercase if (plaintext[i] > '`' && plaintext[i] < '{') { if (...
user avatar
  • 15
0 votes
2 answers
90 views

How to invoke command line argument functions outside of main? caesar.c

Let us say I want to create a separate function for lines 11-25 (check comment for reference) in my code as a separate "argument checker" function. Something similar to how I have my decrypt ...
user avatar
  • 1
1 vote
1 answer
717 views

I have "handles non-numeric key timed out while waiting for program to exit" problem inPset 2 and I can't solve it

here is my code: #include <cs50.h> #include <stdio.h> #include <string.h> #include <ctype.h> #include <math.h> #include <stdlib.h> int main(int argc, string argv[]...
user avatar
0 votes
1 answer
36 views

Testing code to validate input using a parenthesis for cs50/pset 2/caesar.c I get error bash: syntax error near unexpected token `)'

Been struggling with this all morning and grateful for any help please! I'm aware that it's not the most elegant code but below weems to work OK with most invalid input that I've thrown at it so far, ...
user avatar
0 votes
1 answer
77 views

Having problems producung the correct result using the text extracts provided by CS%). I cant see where it goes wrong when finding the correct grade

CODE: #include <cs50.h> #include <stdio.h> #include <ctype.h> #include <string.h> #include <math.h> int main(void) { // DECLARE LETTER, WORD & SENTENCE COUNT int ...
user avatar
0 votes
1 answer
62 views

Pset2 readability

im trying to write this code in a particular way but my programme seems to keep getting the letter counts wrong. running debug 50 it seems that the bool i have created (letter) does not change from ...
user avatar
0 votes
1 answer
47 views

PSET2 Caesar (BARFOO/BaRFoo error)

Hi everyone and I'm sorry if this has been asked here, but I've spent hours online trying to figure out why only the mixed (upper and lower) tests failed. I don't know what I'm overlooking or missing ...
user avatar
0 votes
1 answer
121 views

pset2 substitution not working

im kinda stuck with pset2, substitution. Any help is appreciated. When trying to convert the plaintext into the ciphertext, the formula just doesnt do anything. I suppose there is something wrong ...
user avatar
0 votes
1 answer
278 views

Segmentation fault in Substitution - Problem Set 2

I have finally finished writing my code for the Substitution question in Problem Set 2, but Check50 tells me that my code has a segmentation fault when there is a lack of key. My code is as follows: #...
user avatar
0 votes
3 answers
460 views

How to reject repeated letters for Substitution in Problem Set 2

I am trying to write some code for the Substitution question in Problem Set 2, but I cannot figure out how to reject the case where a user gives a key with repeated letters. My code thus far is as ...
user avatar
0 votes
1 answer
170 views

Problem Set 2 - Caesar

I am very new to coding. Prior to starting CS50, I have had no experience in coding at all, so pardon me if my questions are trivial. I am trying to write some code for 'Caesar' in Problem Set 2 and ...
user avatar
0 votes
1 answer
66 views

Can't fix logical problem, pset2 substitution

I can't fix this logical problem. I have a check_alpha function which should return if all characters are alphabetic. bool check_alpha(char key[]) { for (int i = 0, n = strlen(key); i < n; i++...
user avatar
0 votes
1 answer
43 views

Improvement in Cash Code

im curently doing pset4, but redoing the psets one by one for practice since I feel like im not yet ready to make pset4. Just finished pset2, Cash. The code is right and works, i was just wondering if ...
user avatar
0 votes
1 answer
200 views

Pset2 - Substitution - "Output not valid ASCII text" error despite correct cipher output

after running check50 I am getting an "output not valid ASCII text" error for the following problems: :( encrypts "A" as "Z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key output not valid ASCII text :...
user avatar
0 votes
1 answer
345 views

Pset2 Readability test fail "complex single sentence" Grade 9 instead of Grade 8

When using check50 or inputting the provided texts, my program passes all but one test; the "complex single sentence" test returns a Grade 9 instead of Grade 8 (Coleman-Liau index returns 8.785455 and ...
user avatar
  • 15
0 votes
2 answers
60 views

pset2 readability. The brackets are in the wrong place but I can't figure out where they should go to make the program work correctly

include include include include include include int letters = 0; int words = 0; int sentences = 0; int main(void) { string text = get_string("Text: "); for (int i = 0, len = strlen(...
user avatar
0 votes
1 answer
27 views

Strlen function does not give the intended output

when I execute this code below with the text: hello world, the result is 5 characters. Why is that? #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { ...
user avatar
0 votes
1 answer
44 views

Caesar fails Check50 due to final "\n"

My Caesar code fails the Check50. While it correctly ciphers the message, it appears that the final new line code is not seen by the Check50. I have tried to understand why for several days, to no ...
user avatar
0 votes
1 answer
68 views

PSET2 caesar. I am having trouble checking to make sure that the key is an integer and that it has two arguments in the command line

#include <stdio.h> #include <cs50.h> #include <math.h> #include <stdlib.h> #include <ctype.h> #include <string.h> int main(int argc, string argv[]) { //are there ...
user avatar
0 votes
1 answer
2k views

Incompatible pointer to integer conversion passing 'int on functions

im new to coding and currently working on pset2, readability, and I keep getting this error and can´t find a way to fix it. #include <cs50.h> #include <stdio.h> #include <math.h> #...
user avatar
0 votes
1 answer
57 views

Having problems with Pset2, argv[1]: program doesn't 'see' it

I'm having a problem with argv[]: the code doesn't seem to 'see' it!! With a key that's either too long or too short, the program behaves as expected (prints out error message, exits). But if I input ...
user avatar
  • 5
0 votes
2 answers
207 views

Caesar doesnt pass "non-numeric key" check

I've read all the other answers I can find about people having a similar problem, but mine doesn't seem to be the same issue. Everyone says to use isdigit first, then use atoi, which is what I've ...
user avatar
0 votes
2 answers
158 views

pset2 substitution - isalpha doesn't seem to recognize letters

I'm relatively inexperienced at programming, but I thought I understood how to use command-line prompts well enough to try the substitution problem. I'm having an issue with isalpha that I don't ...
user avatar
1 vote
1 answer
178 views

Check50 for caesar, pset2 returns an error "Not valid ASCII text" twice, even though it encrypts correctly for the same text used in check50

Okay, the code is given below (forgive me if there are too many comments!!). Please help!! Code: //the objective of the program is to create a simple encryption of the text inputted by the user with ...
user avatar
0 votes
3 answers
249 views

I'm getting an for error expected expression. What exactly I'm I doing wrong?

I mainly want my else statement to work, but it's not working. int main(int argc, string argv[]) { if (argc != 2) { printf("Usage: ./caesar key\n"); } else if (argc == 2) { for (int i = ...
user avatar
  • 23
0 votes
2 answers
299 views

pset2 - Caesar. Code works but fails check50. Expected and actual output match

Sorry, I know this has been asked before but I have read all the answers and nothing works! Please help. ERRORS :) caesar.c exists. :) caesar.c compiles. :) encrypts "a" as "b" using 1 as key :( ...
user avatar
0 votes
1 answer
57 views

Why do i get these errors? i am new to programming so please be easy on me. The errors are in the body

#include<stdio.h> #include<cs50.h> #include<string.h> #include<ctype.h> bool check_validity_key(string s); int main(int argc, string argv[]) { if (!check_validity_key(argv[...
user avatar
0 votes
1 answer
276 views

I have a segmentation fault in Caesar in pset 2

Okay, first time writing here and I am a complete noobie. The program compiles and I have run the debugger, and it seems that I have a segmentation fault which I have marked. Also, I have used a lot ...
user avatar
0 votes
2 answers
57 views

pset2 caesar - showing "output not valid ASCII text once"

#include <stdio.h> #include <cs50.h> #include <ctype.h> #include <string.h> #include <stdlib.h> int cypher(string k, char p); int main(int argc, string argv[]) { if ...
user avatar
  • 992
0 votes
1 answer
335 views

pset2 readability. im getting 8 instead of 7th gread

Anyone knows why i get this error? :) readability.c exists :) readability.c compiles :( handles single sentence with multiple words expected "Grade 7\n", not "Grade 8\n" :) handles punctuation ...
user avatar
  • 1
0 votes
1 answer
39 views

What do I do if I get "too few arguments to function call"?

What do I do if I get "too few arguments to function call"? Here is my code: #include <cs50.h> #include <math.h> #include <stdio.h> int main(void) { // Declare and ...
user avatar
0 votes
1 answer
57 views

Copying an array (string) to new array after light mutating (pset2 readability)

I'm working on the readability task in pset2. I've made a new function which is going to count each letter in a string. What I want to do, is to get a user's input string, save it in a variable text ...
user avatar
0 votes
1 answer
155 views

Cs50, cipher text not printing

When i run my code, everything seems to be fine apart from the printing of the ciphertext, and the code doesnt seem to be getting passed the for loop of the string length of plain. Any ideas? #...
user avatar
0 votes
0 answers
19 views

I was doing problem set 2 for CS50x 2020 and I wanted to know why this is wrong

include int main(void) { k = get_int("Enter a number: ") char str[20]; printf("Enter message"); gets(c); for (i = 0; i < strlen(str); i ++) { if (islower(str[i]) {...
user avatar
  • 1
0 votes
1 answer
113 views

Pset2 Functions video - Valid triangle solution

I tried to create a solution involing some of the new things learned in the weeks lecture such as arrays. How can I improve on this and why is my do loop to obtain a positive float value for the ...
user avatar
  • 3
0 votes
1 answer
71 views

PSet 2 -- Substitution set:

All the check50 inputs are working fine, apart from the one where the input is "The quick brown fox jumps over the lazy dog". In this case my code works fine till 'jumps' and after that the code doesn'...
user avatar
0 votes
2 answers
362 views

PS2 substitution

I am trying to check that the substitution key contains all the alphabets but am getting error: expression result unused for this line of code: s, l ++; Can anyone help, this is my code as of now: ...
user avatar
  • 23
0 votes
2 answers
100 views

Counting apostrophe

How do I count the character apostrophe ( ' ) in a sentence. When I tried: if (s[n] == (''') error message showed "expected expression". missing terminating ' character. Other characters counting ...
user avatar
0 votes
0 answers
89 views

PSET Make Readability

i am having some problems trying to execute make readability. Can you help me? Thanks in advance!
user avatar
0 votes
1 answer
84 views

datatype string is malfunctioning in pset2 2020

I am currently working on pset2 cs50 2020. The Ceasar's cipher problem. I have managed the code for the first few steps and I think I know how to do the rest however I'm having an issue declaring ...
user avatar
  • 19
0 votes
2 answers
65 views

pset2 readability. cannot compile although int is declared and code is complete. could someone please look into?

#include<cs50.h> #include<stdio.h> #include<string.h> #include<ctype.h> #include<math.h> int main (void) { string text=get_string("text:\n"); // to count ...
user avatar
0 votes
0 answers
30 views

Caesar (Pset2): When i print out ciphertext, some additional characters, that are not supposed to be part of the array, print out. How do i fix that? [duplicate]

// Receive plaintext string text = get_string("plaintext: "); int t = strlen(text); char ciphertext[t]; //Array assignment for (int i = 0; i < t; i++) { // Plaintext to Ciphertext ...
user avatar

1 2 3
4
5
26