π₯Executing system commands
In this section we shall see how to execute system commands using the exec functions
#include <errno.h>
int main(int argc, char* argv[], char* envp[]){
// argc = argument count
// argv = argument vector
// envp = environment pointer
// errno stores the error code (if any) of the process in which the main thread is running
return errno;
}#include <stdio.h>
#include <math.h>
#include <string.h>
int str_to_int(char* c){
int x = 0;
int n = strlen(c);
for(int i=0;i<n;i++)
x += (c[i] - 48)*pow(10,n-i-1);
return x;
}
int main(int argc, char* argv[]){
int sum = 0;
for(int i=1;i<argc;i++)
sum += str_to_int(argv[i]);
printf("Sum = %d",sum);
return 0;
}Output
Output
Output
Last updated