cs50

undefined reference to `__ubsan_handle_nonnull_arg' [duplicate]

独自空忆成欢 提交于 2020-01-06 14:47:28
问题 This question already has answers here : Using GCC Undefined Behavior Sanitizer (2 answers) Closed last year . I have been working on the problem set speller for the last days and so far this is what I have. Unfortunately, it does not compile and I am a bit lost. I would be really grateful if somebody can help me out and tell me, what I am doing wrong. // Implements a dictionary's functionality #include <stdbool.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h

Harvard CS50 Library , Need Help Installing on Mac OS X

给你一囗甜甜゛ 提交于 2020-01-06 04:55:05
问题 I'm taking this course from cs50.tv, which is Harvard extension school and in the course they are using a library they made called cs50 , on this link its available for download https://manual.cs50.net/CS50_Library#Mac_OS I downloaded the zip file and unzipped it, and then I open the terminal and cd my way to the library directory, but every time I follow the steps in the manual. Right after I do this command gcc -c -ggdb -std=c99 cs50.c -o cs50.o I get this error in the terminal cs50.c:15:16

segmentation fault in C by replacing a string's letter [duplicate]

天涯浪子 提交于 2020-01-05 05:24:25
问题 This question already has answers here : Modifying String Literal [duplicate] (4 answers) Closed 3 years ago . I want to replace a character (for example the second one) from a string. What's wrong with my code? It can compile, but instead of doing what I need it give me a Segmentation fault. Thanks! #define _XOPEN_SOURCE #include <unistd.h> #include <stdio.h> #include <cs50.h> #include <string.h> int main (int argc, string argv[]) { string key="abcd"; key[1]='f'; } And after compiled my code

malloc vs array in C

て烟熏妆下的殇ゞ 提交于 2020-01-02 04:52:06
问题 I am taking a MOOC course CS50 from Harvard. The last lecture I had was about memory allocation and pointers (two concepts which are absolutely new to me). What was taught is that malloc(10*sizeof(char)) allocates enough bytes on the heap to store 10 characters and returns a pointer to the first byte which can be saved in another variable as follows char *x = malloc(10*sizeof(char)) . To free the memory one would use free(x) . But there is another way to make a computer to reserve enough

Vigenere Cipher Black Hawk Down

淺唱寂寞╮ 提交于 2019-12-25 19:58:30
问题 I cannot figure out why this thing doesn't scramble correctly. I read some other posts on this cipher and as far as I can tell I'm using the exact same algorithm as they are... The areas commented out are tests I tried to make sure everything was passing through correctly. I believe it all goes through correctly then fails in the algorithm. #include <stdio.h> #include <cs50.h> #include <string.h> #include <ctype.h> #include <stdlib.h> string get_message(void); string scramble(string key,

Vigenere Cipher Black Hawk Down

孤街浪徒 提交于 2019-12-25 19:58:07
问题 I cannot figure out why this thing doesn't scramble correctly. I read some other posts on this cipher and as far as I can tell I'm using the exact same algorithm as they are... The areas commented out are tests I tried to make sure everything was passing through correctly. I believe it all goes through correctly then fails in the algorithm. #include <stdio.h> #include <cs50.h> #include <string.h> #include <ctype.h> #include <stdlib.h> string get_message(void); string scramble(string key,

cs50 library wont link to file in cs50 appliance

自作多情 提交于 2019-12-24 12:21:42
问题 I'm not new to programming but I'm also far from an expert. I'm taking CS50 from Harvard online and I'm trying to use the functions from the cs50 library that are supposed to work automatically inside the cs50 appliance (Fedora virtual machine version 19-2). My problem is that when I #include <cs50.h> and compile like he does in the lectures, I get an error message. Here's a simple program from a lecture slide. #include <cs50.h> #include <stdio.h> int main(void) { // ask user for input printf

check that command line input is numeric

戏子无情 提交于 2019-12-24 03:12:12
问题 I'm new to C and want to write a simple programme to be called with exactly two command line arguments (the first one being the programme's name, the second one being a string). I have validated the number of arguments and now want to validate the input only contains digits. #include <stdio.h> #include <string.h> #include <ctype.h> #include <cs50.h> int main(int argc, string argv[]) { if (argc == 2) { for (int i = 0, n = strlen(argv[1]); i < n; i++) { if isdigit(argv[1][i]) { printf("Success!

Where is the mistake in my code to perform Binary Search?

99封情书 提交于 2019-12-18 09:03:23
问题 I was writing up code for a binary search algorithm. Code: #include "cs50.h" int main(void) { int n = GetInt(); int value = GetInt(); int values[n]; for (int i = 0; i < n; i++) { printf("Put in number %i ", i + 1); values[i] = GetInt(); } int mid = (n - 1) / 2; int en = 0; int ex = n - 1; for (int i = 0, xt = i + 1; i < xt; i++) { if (value > values[mid]) { en = mid; mid = (en + ex) / 2; } else if (value < values[mid]) { ex = mid; mid = (en + ex) / 2; } else if (value == values[mid]) { printf

Differentiating words in trie

一曲冷凌霜 提交于 2019-12-14 03:24:58
问题 I have a word "all" in my trie and a word "alter" but "alt" is not a word in the trie. But when I check for "alt" it still returns true because is_word is true as "all" was a word. How am is supposed to work this error. //Here's the code typedef struct node{ bool is_word; struct node *children[27]; } node; unsigned int wsize=0; node * root; bool check(const char* word) { // TODO node *chrawler=root; for(int i=0;i<strlen(word)-1;i++) { int t; if(word[i]>=65&&word[i]<=90) { t=word[i]-'A'; }