cs50

Is there a way to structure my code to add up numbers across multiple if else statements?

我怕爱的太早我们不能终老 提交于 2020-03-28 06:39:47
问题 Right now this code takes all the products of an inputted series of digits and prints them. I want to be able to add these products together but I am struggling with how to structure it, given the if else conditions. It needs to be able to output the total products of every 2nd digit starting from the second last and then add those products. Any advice on how to structure this much appreciated. // Define libraries #include <cs50.h> #include <stdio.h> #include <math.h> int main(void) { //

Segmentation Fault for a Program that Indexes Words from a File

泪湿孤枕 提交于 2020-03-23 08:02:56
问题 I am getting a segmentation fault for a C program that first reads the characters of a given file, identifies words, indexes words, and prints the first word. I have been troubleshooting for a long time but cannot seem to find what the error is. #include <stdio.h> #include <stdlib.h> #include <cs50.h> #include <string.h> int main (int argc, char *argv[]) { if (argc != 2) { printf("Usage: ./test15 text\n"); return 1; } char *file = argv[1]; FILE *ptr = fopen(file, "r"); char ch; int i = 0; int

Segmentation Fault for a Program that Indexes Words from a File

允我心安 提交于 2020-03-23 08:02:33
问题 I am getting a segmentation fault for a C program that first reads the characters of a given file, identifies words, indexes words, and prints the first word. I have been troubleshooting for a long time but cannot seem to find what the error is. #include <stdio.h> #include <stdlib.h> #include <cs50.h> #include <string.h> int main (int argc, char *argv[]) { if (argc != 2) { printf("Usage: ./test15 text\n"); return 1; } char *file = argv[1]; FILE *ptr = fopen(file, "r"); char ch; int i = 0; int

关于CS50课程

寵の児 提交于 2020-02-05 05:19:05
CS50课程是美国哈佛大学的一门计算机课程,全名为“Introduction to Computer Science ”,主讲人David Malan。 已经看了两期的CS50课程了,实在被美国的老师和教育方式所吸引。在此写下几点感受: 1.课程用CS50为名字代替其复杂的全名。仅用简单的字母和数字便能表示这门课程,尽管仅从CS50不能直接获得这门课所教授的内容,但是在简洁方面,这种方式能给人很深刻的记忆,对于想知道其教授的内容的同学也可以在网络中查到。其实David Malan已经将这门课带到了一种品牌的高度,CS50更加适合作为这个品牌的名字(后面还会说到)。 2.老师讲课的方式。David Malan在讲课时极富有激情,很能够感染到现场的同学们,不像很多国内老师,上课死气沉沉,学生们也昏昏欲睡。同时,他的讲课方法也很有趣,不时的找volunteer上台配合,不时播放youtube上的视频以吸引同学们同时引出自己的内容。第一课中,他为了讲明如何查找信息,找了一名volunteer把整部电话号码本撕个粉碎。我想对于我们的老师,谁也不会这么做。一是成本,二是中庸的思想。 3.老师的性格。David Malan很是平易近人,能够录公开课的老师一般也都很强了,至少在知名度方面很高。但是David Malan的笑容依然很自然,对待学生也没有老师和学生的那种隔阂感觉

How to link the cs50 C library in gcc on windows

烂漫一生 提交于 2020-01-25 07:03:25
问题 I'm new to С programming and have been trying to compile my code using MinGW/GCC, but I try to include cs50 (cs50.c, cs50.h) library, and the compiler can't find it. Help me compile who knows what's going on. I tried to give such command: gcc -LC:\Users\apple\Desktop -lcs50 mario.c But the result is this: c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lcs50 collect2.exe: error: ld returned 1 exit status Or: c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../..

warning: implicit declaration

跟風遠走 提交于 2020-01-24 09:36:06
问题 I have an assignment I am supposed to turn in for my computer science MOOC CS50. In it I have to turn in the assignment over the Harvard website, but it won't accept my code while it says "Warning: implicit declaration..." Is there a way to shut that off? I have two functions that I am using, islower() , and isupper() , and they are what is causing the hangup. My code seems to work just fine, it compiles and everything. BTW if anyone wants to tell me how crappy my code is that would be

Creating a “Mario Style Pyramid” [duplicate]

依然范特西╮ 提交于 2020-01-20 08:09:06
问题 This question already has answers here : Making a Hash Pyramid (2 answers) Closed 3 years ago . I'm going through the Harvard CS50 online course and one of the problems is to create a "mario style pyramid" using spaces and hashes. I've got the spaces solved but the hashes are giving me trouble. Here's the code: #include <stdio.h> #include <cs50.h> int main(void) { //get height between 1 and 23 int height; do { printf("Please enter a height: "); height = GetInt(); } while (height < 1 || height

update sqlite database in python after the item from dropdown suggestions selected

孤人 提交于 2020-01-15 09:27:38
问题 My program must update table "idlist" in python after the item was selected from drop down suggestions in js. User selects the item, after that POST request in python adds it to the "idlist" table. As I run the program I get the following error message: I am grateful for your ideas and suggestions: Here is my python code: def search(): """Search for books that match query""" if request.method == "GET": if not request.args.get("q"): return render_template("adjust.html") else: q = request.args

What is signed integer overflow?

孤人 提交于 2020-01-14 07:11:51
问题 I'm learning C from CS50. When I run my code, it says 'signed integer overflow'. #include <stdio.h> #include <cs50.h> int main(void) { int x = 41; int c = 0; while(x>=25) { c = c+1; } printf("%i\n", c); } Can someone explain what that means? 回答1: Your while condition will always be true, meaning the loop will run forever, adding 1 to c in each iteration. Since c is a ( signed ) int it means it will increment slowly to its max value, and after that the next increment would be UB (undefined

Vigenere Cipher

微笑、不失礼 提交于 2020-01-08 04:17:46
问题 I am trying to make Vigenere Cipher in C. https://www.youtube.com/watch?v=9zASwVoshiM this is info about Vigenere Cipher. My code works doesnt work for certain cases like encrypts "world, say hello!" as "xoqmd, rby gflkp!" using "baz" as keyword instead it encrypts it as xomd, szz fl. Another example is: encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword but instead it encrypts it as CakGo. My code is given below please help me out: #include<stdio.h> #include<cs50.h> #include<ctype.h>