cs50

Adding a header file to Xcode

让人想犯罪 __ 提交于 2019-12-14 01:50:23
问题 I'm trying to add a C library to Xcode. I downloaded the library from an online C class, and the zipped file contains two files: cs50.c and cs50.h . I installed these files using the following commands: gcc -c -ggdb -std=c99 cs50.c -o cs50.o ar rcs libcs50.a cs50.o rm -f cs50.o chmod 0644 cs50.h libcs50.a sudo mv cs50.h /usr/include sudo cp libcs50.a /usr/lib When building the project, I get the following error message: Undefined symbols for architecture x86_64: "_GetString", referenced from:

Re-prompting a user until he/she enters a positive integer value greater than 1

百般思念 提交于 2019-12-13 23:52:27
问题 I'm solving CS50 (problemset 1) i.e water.c. It asks user to write a program that prompts the user for the length of his or her shower in minutes (as a positive integer) and then prints the equivalent number of bottles of water (as an integer). 1 min of shower = 12 bottles consumed MAIN PROBLEM: The problem is that we have to ensure that the user inputs a positive number of minutes otherwise it keeps on re-prompting his back to input/scanf statement. As long as he enters he enters length<=0,

My code for recover.c recovers jpegs correctly but does not pass cs50 check [closed]

六月ゝ 毕业季﹏ 提交于 2019-12-13 23:38:04
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Here is the code. I am a beginner at C language so any suggestions to shorten my code will be greatly appreciated. I checked all the 50 images and they look perfect but the code doesn't pass the cs50 check. int main(void) { FILE* source = fopen("card.raw", "r"); uint8_t jpg[512]; int direct = 0; int jpgcounter =

Caesar cipher in C working for lower not upper

China☆狼群 提交于 2019-12-13 22:12:30
问题 Cipher works for islower portion but not isupper portion. For instance if I give a key of 3 and enter I like pie!! to be encrypted, I get O olnh slh!! I also tried HELLO and got NKRRU . The isupper portion is also returning punctuation instead of just letters. I also have not figured out why the original message is being altered to match the cipher message. #include <stdio.h> #include <cs50.h> #include <stdlib.h> #include <ctype.h> #include <string.h> int main (int argc, string argv[]) { /*

CS50 Pset1 Cash error “expected identifier or '('” meaning?

陌路散爱 提交于 2019-12-13 08:58:03
问题 #include <stdio.h> #include <cs50.h> #include <math.h> int main(void) { { float dollars; // prompt user for "0.00" value do { dollars = get_float("Change owed: "); } while(dollars <= 0); } // print amount of coins used for change printf("%f\n", get_change(dollars)); int get_change(float dollars); { //calculate which coins will be used int cents = round(dollars * 100); int coins = 0; int denom[] = {25, 10, 5, 1}; for (int i = 0; i < 4; i++); { coins += cents / denom[i]; cents = cents % denom[i

CS50 - Recovery - Manipulating Card.raw PSET3

泄露秘密 提交于 2019-12-13 08:41:30
问题 So I'm a newbie struggling (drowning really) with C, trying to work my way through CS50. I'm working on the 'Recover' exercise, trying to recover jpegs from the card.raw file. Through Googling, I have learnt that by typing xxd -l 2400 card.raw (char is 'L') in terminal, I can display bytes 0-2384 inclusive in terminal, which are in the following format: 0000000: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000950: 0fe0 c11b e555 8f20 33cc fbfe 559e 8eee .....U. 3...U... Q1: I

Why is implicit declaration of gets() not allowed in C99?

旧街凉风 提交于 2019-12-12 18:24:48
问题 I am starting to learn programming in C language the book I am refering to code shows some source code with gets() and my IDLE recognises it as well. But still while compiling it, my compiler doesn't agree with it. Can anyone help me out? I am using gets() in the main function and using clang as the compiler. 回答1: Expanding on my comment: First, never use gets() , for any reason, even in toy code. If you see it in an example program, ignore the example and move on. It was deprecated in C99

Beginning C Program

冷暖自知 提交于 2019-12-12 15:44:34
问题 I was working though some beginning problem sets with Harvard's online CS50 class. I got the problem to work correctly but I was wondering if there would possibly be a cleaner or better way to get the program to work. The goal of the program is to print a right-aligned pyramid comprised of hash-tags and space characters. Any guidance in regards to style or tricks would be very welcome. /* Creating the mario program, whose goal is to create a * pyramid by accepting input from the user to get

CS50: pset2 / initials:- I've got code that works but I feel like I am taking a shortcut with setting my array size

喜你入骨 提交于 2019-12-12 06:57:21
问题 So I am working away on the 'less comfortable' version of the initials problem in CS50, and after beginning with very verbose code I've managed to whittle it down to this: #include <cs50.h> #include <ctype.h> #include <stdio.h> #include <string.h> int c = 0; int main(void) { string name = get_string(); int n = strlen(name); char initials[10]; // first letter is always going to be the first initial initials[0] = name[0]; // count through letters looking for spaces + add the first letter after

Vigenere Cipher only works up until dealing with a space(“ ”) in C - why?

╄→гoц情女王★ 提交于 2019-12-12 06:50:08
问题 #include <stdio.h> #include <cs50.h> #include <string.h> #include <stdlib.h> #include <ctype.h> int main(int argc, string argv[]) { string k = argv[1]; string s = GetString(); int l = strlen(k); for(int i = 0, n = strlen(s); i < n; i++) { if(s[i] >= 65 && s[i] <= 90) { int i2 = ((s[i]-65) + (k[i%l]-97)) % 26; printf("%c", i2+65); } else if(s[i] >= 97 && s[i] <= 122) { int i2 = ((s[i]-97) + (k[i%l]-97)) % 26; printf("%c", i2+97); } else { printf("%c", s[i]); } } printf("\n"); return 0; } I