stdio.h is a header file from the C Standard Libraries, and their implementations are in the libc.a file, due to his common and extended use, this file is automatically linked by the compiler as if the -lc argument was especified on the compiler command like this:
clang hello hello.c -lc
On the other hand, the cs50 library is and external library created ...
x++ - Post-increment operator
++x - Pre-increment operator
x++ - x is incremented after the current statement is evaluated.
++x - x is incremented before the current statement is evaluated.
Well, lets say we have a function called foo which has a local variable x:
int x = 0;
In this function, x is ...
The make utility actually calls the clang compiler with special options that can be set for a project.
When I run make in the ide it actually runs the following:
clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow temp.c -lcrypt -lcs50 -lm -o temp
Most of that is unimportant to understand ...
you don't have to do that because there are already notes for each lecture in a PDF form which you can find under each lecture video in edX.
you may still want to take your own notes (maybe even on the notes provided by the staff). in general terms, there are purposes of taking notes:
to summarize things so that you don't have to go through everything ...
You are in the wrong directory, change the directory to where your file is stored i.e. Desktop here
jharvard@appliance (~) : cd ~/Desktop
jharvard@appliance (~) : make f2c
jharvard@appliance (~) : ./f2c
Styles are important because they specify good coding habits, which gives you comfort when working in a team, as everyone would be following the same convention, so it will be easier for others to read your code( and vice versa).
CS50 has a online Style Guide that has a good description to stylize comments, conditions, switches, functions, indentation, ...
I suppose this is your hello-world program
which is SAVED as hello.c in your Dropbox folder. Use the following command in terminal to proceed to that folder.
Now, you have the source code of the program with you, but not an executable. You need to make ...
Typically and according to the standard, the return value of main should be of type int which obviously means that you should return an int value from main.
However, you don't really have to do that in C99/C11 as in these standards, if you do not explicitly return an int value from main, the value 0 is returned automatically.
From C11 standard:
Does cs50.h have a function called get_long_long?. There is no function by that name listed in the CS50 Reference. And notice this from the spec:
Now, get_long itself will reject hyphens (and more) anyway:
It looks like get_long_long has been deprecated in the 2019 version of the course.
The program is stuck in an infinite loop. Look at the while loop setup:
while(credit_number >= 0) // runs the loop until the credit card number is l
i = credit_number % 10; credit_number = credit_number - i;
The first pass subtracts the least significant digit from the cc number, so 371449635398431 becomes 371449635398430. From there on, i is ...
You make a new file by clicking the green plus sign at the top, next to where it says the name of the file you are currently on. On your keyboard, then do command shift S. It will give you options for where to save the file and what the name should be. Name it pseudocode.txt and put it in your mario folder. If this helps, click the check mark or upvote it.
That example doesn't say what data type x and y are, but generally you can assume that numerical variables are real numbers in programming, unless specified otherwise.
There is a way to work with complex numbers in C, but you'd only use it for applications specific to complex numbers. Also, if x and y were complex, x < y isn't defined in the standard ...
Its good that you're thinking about how to make the code more efficient. Kudos to you!
Yes, repeating code is a red flag that things can be simplified. But here, the code is very similar but not the same. It's only the same pattern performed on different variables. It's good that you recognize that there may be a better way, but it's also very important to ...
About the first error in line 10 , you cant declare a vatiable twice , you can only assign it more than once , so you need to delete the float type declaration which is inside the do while loop.
When you want to reduce a number you need to assign it then substract not just substracting the variable or you could use the increment syntax c -= 1.00 and its ...
It's an issue called variable scope, something that will be explained later. Simply put, a variable only exists within the surrounding pair of curly braces where it is created.
In Prof. Malan's example, the variables are created inside the curly braces that contain all of main(). In your case, x only exists inside the do/while loop and is destroyed when ...
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 ...
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 ...
Simply put, c doesn't exist because it was never declared, and no value has been assigned to it. I could explain in detail, but the following site has already done it very nicely, including an example that is very similar to your code with all the missing pieces. ;-)
If this answers ...
Follow the link in the source code to the ioccc page. Follow some of the links to find out what it's all about. It's very cool. Then search the original page for "thad" (it's a winning entry from 2000). There you will find some links. Copy the Makefile to your working directory. Follow the instructions in thadgavin.hint. Make sure your source is named ...
Good question. There is no requirement to capture a return value. Just because a function returns a value doesn't mean that the calling code needs to do anything with it. For many functions, like printf, it is common to disregard the return value. However, when there are bugs in a program, those return values can become useful in diagnosing and debugging.
Say you have written a program named example.c
First you compile your program like so
Then you run it like so
I tell you these because I see you have tried many times to do them in your terminal.
If you want to terminate a program, before it does itself, you press Ctrl+C.
In your case, you compiled adder2.c using make adder2. ...
The if/else if/else conditions are used in the following way:
// code to execute
// code to execute
// code to execute
// code to execute
else if (condition2)
// code to execute
else if (condition3)
else is your last resort kind of command its like
if this then
else if this then
and finally when you cant think of any other condition you say you know what MR Computer if none of the conditions are met.
just do this
you said else and then gave a condition. So the computer is yelling at you that " First you said you ...
Have you watched the lectures and/or the sections for week 1? Being able to research the correct syntax is a vital skill.
The data you pass to printf must be encapsulated in parentheses.
printf ( "blahblah" );
Actually, you don't really have a problem. You just need a little instruction on a couple of nuances that you're tripping on.
First, make is saying up to date because the output of the compiler, file "hello", is current because hello.c has not been changed since the last time you ran "make hello". If you were to edit hello.c and make any changes,
Some of the "Shorts" in Week 0 and Week 1 dip a little into this (not much!) but they do provide a little insight into where you can go and do further research to find out the answers you may be looking for. Particularly, you can view the manual pages for whatever you are looking for in c. For example if you want to see the man page for the function printf, ...