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
2answers
10 views

getting error on caesar

I keep getting an error on the last else idk what's wrong with that code. #include <cs50.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> ...
0
votes
1answer
12 views

pset2 Readability test question

This is what I have so far. I realized that when counting letters there are more symbols you must exclude, but I am not sure how to do that. Also, my program isn't running for some reason and I am not ...
0
votes
1answer
14 views

Trying to do pset 2, but it doesn't even accept my input. What am I doing wrong?

#include <stdio.h> #include <cs50.h> #include <ctype.h> #include <string.h> #include <math.h> int check(int c, string key); int main(int argc, string argv[]) { int ...
0
votes
1answer
25 views

check50 in pset2

I won't post my code, because, as far as I could tell, it works fine, but I keep on getting this when I run check50 and I don't know know exactly what it means or how to fix it. My code runs perfectly ...
0
votes
1answer
17 views

clarification validating command line arg

thanks for the answer. I tried to use a for loop, like this, for (int i = 0; i <= argc; i++) { if (isalpha(*argv[1])) { printf ("Usage: ./caesar ...
0
votes
1answer
36 views

I get segmentation fault after this line and I don't know why

I get segmentation fault at this point in my code and I can't figure out why string convert(string text, int num_copy) { string new_index = NULL, answer; for (int j = 0; ; j ++) { if (isupper(text[...
0
votes
2answers
32 views

I keep getting segmentation fault and I don't know why

I'm trying to print the value of argv[1] to check if the program will run as expected. It compiles fine, but I keep getting 'segmentation fault' when the program runs. #include <cs50.h> #include ...
1
vote
2answers
36 views

My Coleman-Liau index gives the wrong answer

the program seems to be running fine but I don't know what went wrong in the index, it just doesn't give the right answer. #include <cs50.h> #include <stdio.h> #include <string.h> #...
0
votes
2answers
25 views

readability errors

I keep getting errors on the int i. idk what's wrong with my code #include <stdio.h> #include <cs50.h> #include <math.h> #include <string.h> int main(void) string text=...
0
votes
3answers
72 views

Why So Many Check50 Errors on Caesar? Results match expected output

Of the 11 Check50 checks, only 4 check out correct but when I run the code with the Check50 inputs, my outputs match the expected outputs, so why so many errors? Here is a link to my Check50 results: ...
0
votes
2answers
35 views

Can't pass the test on readability

So, I think function 'round' in one case does rounding to the Grade 8, instead of Grade 7. But, if I remove it, another text getting wrong grade. in both cases the grade of either one text is wrong. ...
0
votes
1answer
19 views

PS2 - substitution

thanks for helping me out :) When I am running my code I get a weird output, an intractable char that is being added randomly to my output. The weird thing is that that the char that is being added is ...
1
vote
2answers
40 views

Hey. Please help me find my mistake. The number of words in my sentences is not counted properly

I tried using debugger but could not figure out where I went wrong. please help #include <stdio.h> #include <cs50.h> #include <string.h> #include <math.h> int main(void) { ...
0
votes
1answer
34 views

Pset 2 Readability

What's going wrong? I think I've got it figured out but I'm unable to compile the program and print out what I want it to say.
0
votes
1answer
34 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....
0
votes
0answers
53 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 ...
0
votes
1answer
60 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 ...
0
votes
0answers
30 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 ...
0
votes
1answer
44 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 ...
0
votes
1answer
13 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++) { ...
0
votes
0answers
14 views

PSET2 Caesar Missing Print Values

I'm having troubles with PSET2. My code for rotating capital letters works, however, when I tried to do it with lower case letters, some characters wont seem to rotate? Here's my code for the ...
0
votes
2answers
36 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 ...
0
votes
1answer
43 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 ...
0
votes
2answers
56 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 (...
0
votes
2answers
33 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 ...
1
vote
1answer
36 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[]...
0
votes
1answer
24 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, ...
0
votes
1answer
27 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 ...
0
votes
1answer
48 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 ...
0
votes
0answers
52 views

Problem set 2: readability.c

#include <stdio.h> #include <cs50.h> #include <ctype.h> #include <string.h> #include <math.h> int letter_counter(string text); int word_counter(string text); int ...
0
votes
1answer
30 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 ...
0
votes
1answer
42 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 ...
0
votes
1answer
72 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: #...
0
votes
2answers
45 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 ...
0
votes
1answer
91 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 ...
0
votes
1answer
46 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++...
0
votes
1answer
31 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 ...
0
votes
1answer
55 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 :...
0
votes
1answer
107 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 ...
0
votes
2answers
47 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(...
0
votes
1answer
14 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) { ...
0
votes
1answer
32 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 ...
0
votes
1answer
44 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 ...
0
votes
1answer
44 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> #...
0
votes
1answer
49 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 ...
0
votes
2answers
103 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 ...
0
votes
2answers
65 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 ...
0
votes
1answer
62 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 ...
0
votes
3answers
35 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 = ...
0
votes
2answers
110 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 :( ...

1
2 3 4 5
24