$ls ascii-table avg.txt case-changer.c env-var-set.c functions_ver2.c output.c ascii-table.c avg-with-garbage.txt env-var exist.sh mph-to-kph.c ascii-table.md case-changer env-var.c functions_ver1.c mph-to-kph_v2.c $cat env-var-set.c #define _POSIX_C_SOURCE 200112L #include <stdio.h> #include <stdlib.h> int main(void) { setenv(“FULLNAME”, “Jack-Benny”, 1); printf(“Your full name is %s\n”, getenv(“FULLNAME”)); return 0; } $gcc env-var-set.c -o env-var-set $ $./env-var-set Your full name is Jack-Benny $
Monthly Archives: July 2022
Fetching values of environment variables
$ls ascii-table avg.txt case-changer.c exist.sh mph-to-kph.c ascii-table.c avg-with-garbage.txt env-var.c functions_ver1.c mph-to-kph_v2.c ascii-table.md case-changer env-var-set.c functions_ver2.c output.c $cat env-var.c #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { /* Using getenv() to fetch env. variables */ printf(“Your username is %s\n”, getenv(“USER”)); printf(“Your home directory is %s\n”, getenv(“HOME”)); printf(“Your preferred editor is %s\n”, getenv(“EDITOR”)); printf(“Your shell is …
Program for changing case
$ls ascii-table avg.txt env-var.c functions_ver1.c mph-to-kph_v2.c ascii-table.c avg-with-garbage.txt env-var-set.c functions_ver2.c output.c ascii-table.md case-changer.c exist.sh mph-to-kph.c $gcc case-changer.c -o case-changer $./case-changer g G v V FF ff $cat case-changer.c #include <stdio.h> #include <string.h> int main(void) { char c[20] = { 0 }; char newcase[20] = { 0 }; int i; while(fgets(c, sizeof(c), stdin) != NULL) { …
The ascii table program
$ls ascii-table.c avg-with-garbage.txt env-var-set.c functions_ver2.c output.c ascii-table.md case-changer.c exist.sh mph-to-kph.c avg.txt env-var.c functions_ver1.c mph-to-kph_v2.c $cat ascii-table.c #include <stdio.h> int main(void) { char c; for (c = 65; c<=90; c++) { printf(“%c = %d “, c, c); /* upper case */ printf(“%c = %d\n”, c+32, c+32); /* lower case */ } return 0; } $gcc ascii-table.c …
Sum and multiplication
$ls first-example first-example.c new-sum.c sum sum.c $cat new-sum.c #define _XOPEN_SOURCE 500 #include <stdio.h> #include <stdlib.h> #include <unistd.h> void printhelp(char progname[]); int main(int argc, char *argv[]) { int i, opt, sum; /* Simple sanity check */ if (argc == 1) { printhelp(argv[0]); return 1; } /* Parse command-line options */ while ((opt = getopt(argc, argv, “smh”)) …
Sum of numbers
$lsfirst-example first-example.c new-sum.c sum.c$gcc sum.c -o sum$cat sum.c #include <stdio.h>#include <stdlib.h>void printhelp(char progname[]); int main(int argc, char *argv[]){int i;int sum = 0; /* Simple sanity check */if (argc == 1){printhelp(argv[0]);return 1;} for (i=1; i<argc; i++){sum = sum + atoi(argv[i]);}printf(“Total sum: %i\n”, sum);return 0;} void printhelp(char progname[]){printf(“%s integer …\n”, progname);printf(“This program takes any number of ” …
Hello World
$lsfirst-example.c new-sum.c sum.c$cat first-example.c #include <stdio.h>int main(void){printf(“Hello, world!\n”);return 0;}$gcc first-example.c -o first-example$./first-exampleHello, world!$