General way of writing and executing a C file
For writing a piece of code in C
Open a text editor (preferably use atom or sublime Text or VS_Code(Preffered)
Writing Code
You can use/copy sample.c file and edit in that and save that with different names
//header file #include <stdio.h> int main() { //Your code goes here return 0; }
Saving your code
Use extension .c (eg: linear.c)
Compiling the code
goto your terminal move to the directory where you have saved your file using command cd eg:
ADITYAs-MacBook-Air:~ aditya$ cd Desktop/study //if your file is saved in the folder study inside Desktop
then press
ADITYAs-MacBook-Air:study aditya$ ls //to confirm your file say linear.c is present or not // this step is not required
then type
ADITYAs-MacBook-Air:study aditya$ cc filename.c //eg: cc linear.c
You can also use Online Compiler for compiling any C program but it is not much efficient
Executing the file
type in the terminal just after compiling the code
ADITYAs-MacBook-Air:study aditya$ ./a.out
Verifying the result
If you are getting output as expected :
then congratulations you are doing a great job
else:
Check the code once again and repeat the procedure
Books for studying C
Feel free to contribute