- This topic has 0 replies, 1 voice, and was last updated 4 years, 1 month ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
aiannum.com has rebranded as Progaiz.com
› Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 1: [C] – Data Types, Operators, Conditional Statements, Loops, and Command Line › Function in C: How to create
Tagged: define function, function, function in C, functions
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
#include <stdio.h>
#include <cs50.h>
int main(void)
{
long creditcardno;
do
{
creditcardno =
get_long("enter");
}
while (creditcardno < 0);
}
[/dm_code_snippet]
The above code accepts positive integers while taking input for credit card no.
The task is now to form a function my_function () that will perform the above task when called in the main function.
All that I can figure out is:
[dm_code_snippet background=”yes” background-mobile=”no” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
#include <stdio.h> #include <cs50.h> long my_function (void);
[/dm_code_snippet]
Will the next line include int main (void) or that will not appear at all.
Is it possible that I form a different c file such as test.c that will include function definition only and this file be called in main function in credit.c. Or both possibilities are there. I can have function defined and called in the same file so that everything can be performed from credit.c file.
Reply
https://cs50.stackexchange.com/questions/42051/function-in-c-how-to-create[learn_press_profile]
