Hot answers tagged

6

First, you'll need to install the cs50 library. Follow this link for more information about how you can install the cs50 library on Fedora! Second, you need to link the library binary file by providing -lcs50 when compiling. So your command should look something like cc condition0.c -lcs50 -o condition0 Notice that you'll probably need a Makefile in case ...


2

Good catch. Actually, c will never be populated with this command if (sscanf(line, " %i %c", &n, &c) == 1). It is a matching failure. From man sscanf: A conversion specification, which commences with a '%' (percent) character. A sequence of characters from the input is converted according to this specification, and the result is placed in the ...


1

Don't worry about the retry. Retry is only displayed when you enter something that is not a number, say a character like "space" or abc. But the problem with your code is that you put the printf statement outside of the do while loop. Remember the do while loop executes the stuff inside first and then does it check the condition. So think about what ...


1

That's GetInt(), not getint(). C is case sensitive.


1

main is a special function. It's the starting point of a C program — it's called somehow magically when you execute the program from the terminal by typing its name in as follows ./programName main can be declared to receive command-line arguments. Command-line arguments are special type of arguments in a sense that they're passed to your program via the ...


1

The only reason that GetInt() would return "Retry" is if it recieved a non-integer from standard input (ie, from your keyboard), as the definition says: /* * Reads a line of text from standard input and returns it as an * int in the range of [-2^31 + 1, 2^31 - 2], if possible; if text * does not represent such an int, user is prompted to retry. Leading ...


1

The problem is that the function get_pyramid_steps is never called by anything in main. It might as well not be there. If this answers your question, please click on the check mark. Let's keep up on forum maintenance. ;-)


1

Solved! I ran "update50" in the terminal twice, and after the second time a prompt came up that told me I'm currently running "pip 9.0.1" and there is an update available for "pip 10.0.1", and told me what command to type for the update. After I entered the command, I waited about 20 seconds, made sure my code was correct and typed make int again - this ...


1

Your line numbers in code and in the error messages don't match, are off by one, so I'd guess you forgot to save, or compiled something else (another file, maybe of the same name in a different directory). A successful make run might print the command used to call the compiler, but the compiler itself will probably not print anything, just create a int file ...


1

The GetInt() function has been deprecated (deleted, last year?) and replaced with the more robust function get_int(). The new getint() function can be given a string as a parameter and it will print that string and then wait for input. For example: int yum = get_int("How many ice cream cones do you want: "); If this answers your question, please click ...


1

Simply put, the file integer, the executable file, doesn't exist. Only the source code file integer.c exists. You need to make integer first, in order to compile the source code and produce the executable file integer. THEN, you can run it with the command ./integer. If this answers your question, please click on the check mark to accept. Let's keep up on ...


1

what you are seeing is a side effect of how get_int works. If you have something like: int num; do { printf("Number: "); num = get_int(); } while (num < 0); And run it, you will see this behavior: Number: -1 Number: foo Retry 2 But if you change your do while to this: do { num = get_int("Number: "); } while num < 0; Then you will ...


1

As one can see on https://github.com/cs50/libcs50/tree/master/src those contain quite some code to keep you from messing up and provide a nice user interface. The simplest alternative would be scanf, which when used in a wrong way can easily lead to security problems ("buffer overflow") or wrong interpretation of results. It's also not always exactly ...


1

implicit declaration of function 'GetInt' is invalid in C99 Though daunting, the compiler makes it very clear - your code implies that you want to use GetInt, but you instead use get_int(). I have found that, at times, the compiler and CS50 library can be very sensitive, so it is best to use the regular version, GetInt(). In the CS50 file, how GetInt is ...


1

You lack the main function, all console programs must have a main function: int main(void) { some code } The error is surely because the compiler thinks that you are going to define or declare a function, the do-while loop is the most appropriate for this case. EDIT All statements must end in semicolons (;) int minutes = get_int() should be: int ...


Only top voted, non community-wiki answers of a minimum length are eligible