CS50: LIKE operator, variable substitution with % expansion

Pass the entire search string as the parameter to the LIKE operator: results = db.execute(text(“SELECT * FROM books WHERE title LIKE :search”), {“search”: f”%{search}%”}).fetchall(); or alternatively concatenate in the database: results = db.execute( text(“SELECT * FROM books WHERE title LIKE (‘%’ || :search || ‘%’)”), {“search”: search}).fetchall();

Usage of uint_8, uint_16 and uint_32

In your 3 cases, before the printf statement, the 4 first bytes of the arr array (in hexadecimal format) are: FF D8 FF E0, which corresponds to 255 216 255 224. Here are explanations of each case: arr[0] has uint8_t type, so its 1-byte value is 0xFF, so printf(“%i”, arr[0]); prints 255, which corresponds to … Read more

CS50 Caesar – ASCII letters and Output format

First of all, you have to follow the specifications of the problem. That is, you have to print out the word ‘plaintext:’ before taking input and print out ‘ciphertext:’ before giving any output. As the checking process is automated, this becomes very important. Notice the case of those words in your problem statement. Secondly, I … Read more

Why is my code giving me segmentation faults?

You should probably have a look at https://en.wikipedia.org/wiki/Segmentation_fault. Basically it means that your code is trying to use data at an address in an invalid way. A common case in C code is something like this: char * cptr = NULL ; cptr = some_function_returning_null(); printf(“%s\n”cptr); The memory at pointer cptr has never been set … Read more