LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I'm a Newbie, need to know what does this code do(and how to execute it in terminal) (https://www.linuxquestions.org/questions/linux-newbie-8/im-a-newbie-need-to-know-what-does-this-code-do-and-how-to-execute-it-in-terminal-4175527191/)

Flamur 12-03-2014 07:18 AM

I'm a Newbie, need to know what does this code do(and how to execute it in terminal)
 
How to exeute a .c file in terminal and what this code do pls.
thnkx for help

Code:

#include<stdio.h>
int main()
{
    fork();
    fork();
    fork();
    printf("Hello");

return 0;

}


gdejonge 12-03-2014 07:35 AM

Hi,

You don't execute a .c file directly in a terminal. You compile it with a c-compiler like gcc or clang to an executable format and execute that.

The program you show would create a number of child processes. But if you don't know what the fork() statement does, I would advise you to get a nice beginners book about C and start off with something simple like
Code:

#include <stdio.h>

int main()
{
    printf("Hello, World\n");
    return 0;
}

Cheers,

Flamur 12-03-2014 01:33 PM

commands
 
i need to know the commands to execute the files, i know already that i nee to compile it first, pls the step bby step commands someone?

gdejonge 12-03-2014 11:31 PM

Hi,

There are already a lot of posts on this site that could tell you how, also reading the man-pages could tell you probably how.
But basic command to compile is:

gcc <inputfiles> -o <executable file>

Example: gcc test.c -o test

To execute:

./test

Cheers,


All times are GMT -5. The time now is 11:27 AM.