LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-03-2014, 07:18 AM   #1
Flamur
LQ Newbie
 
Registered: Dec 2014
Posts: 2

Rep: Reputation: Disabled
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;

}

Last edited by Flamur; 12-03-2014 at 01:45 PM.
 
Old 12-03-2014, 07:35 AM   #2
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
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,
 
Old 12-03-2014, 01:33 PM   #3
Flamur
LQ Newbie
 
Registered: Dec 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
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?
 
Old 12-03-2014, 11:31 PM   #4
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
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,
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Execute cd in new terminal aihaike Linux - General 2 07-22-2013 09:12 PM
code that will never execute hydraMax Programming 6 05-25-2011 11:50 PM
Execute code for n time nmartins Programming 2 04-23-2011 01:28 PM
execute command from c code alaios Programming 3 06-06-2005 05:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration