Search
 
SCRIPT & CODE EXAMPLE
 

C

how to compile and run a program in c

//for UBUNTU and other linux distros
gcc -o my_program my_program.c
//to run..
./myprogram
Comment

How to run C program using command

gcc <file-name.c> -o <output-file-name>
Comment

to execute a program using C

julien@ubuntu:~/c/shell$ cat exec.c
#include <stdio.h>
#include <unistd.h>

/**
 * main - execve example
 *
 * Return: Always 0.
 */
int main(void)
{
    char *argv[] = {"/bin/ls", "-l", "/usr/", NULL};

    printf("Before execve
");
    if (execve(argv[0], argv, NULL) == -1)
    {
        perror("Error:");
    }
    printf("After execve
");
    return (0);
}
julien@ubuntu:~/c/shell$ gcc -Wall -Wextra -Werror -pedantic exec.c -o exec
julien@ubuntu:~/c/shell$ ./exec 
Before execve
total 120
drwxr-xr-x   2 root root 61440 Dec  4 00:08 bin
drwxr-xr-x   2 root root  4096 Jul 19 13:47 games
drwxr-xr-x  58 root root  4096 Oct 27 13:10 include
drwxr-xr-x 138 root root  4096 Dec  4 00:08 lib
drwxr-xr-x   3 root root  4096 Nov 10 09:54 lib32
drwxr-xr-x   3 root root  4096 Nov 10 09:54 libx32
drwxr-xr-x  10 root root  4096 Jul 19 13:42 local
drwxr-xr-x   3 root root  4096 Jul 19 13:48 locale
drwxr-xr-x   2 root root 12288 Dec  2 11:03 sbin
drwxr-xr-x 295 root root 12288 Jul 27 08:58 share
drwxr-xr-x   6 root root  4096 Dec  1 11:39 src
julien@ubuntu:~/c/shell$
Comment

PREVIOUS NEXT
Code Example
C :: C program to input the month number and output the month name using switch statement 
C :: absolute value of intel intrinsic 
C :: cifras de un numero en c 
C :: chevront de vlavier 
C :: esp8266 wifi.config does not work 
C :: what is type casting in c programming 
C :: definir função em c 
C :: getline() in c 
C :: how to check the word is present in given char array in c 
C :: c read binary file 
C :: scan c 
C :: C# special character display 
C :: calling of a void in c 
C :: boolean operators in c++ 
C :: c malloc 
C :: national festivals of india in hindi 
C :: XAudio2 C 
C :: parcel-builder put image in sub folder 
C :: retoure a la ligne C 
C :: c %d 
C :: C static libraries (creating object files) 
C :: minimun number of moves in c 
C :: c to assembly converter online 
C :: python to java translator online 
C :: c byte vs char 
C :: mettre int dans string c % 
C :: Print fabionci with fork in C 
C :: fread condition 
C :: c++ sum of ascii string 
C :: changing an item in an array in c 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =