You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
435 B
C

#include <stdlib.h> //getenv, atoi
#include <stdio.h> //printf
int main()
{
// pointer to a char
char *repstext = getenv("reps");
// atoi reads in the string and converts it to a integer value.
// This is the tenary operator 'condition ? value_if_true : value_if_false'
int reps = repstext ? atoi(repstext) : 10;
char *msg = getenv("msg");
if (!msg)
msg = "Hello.";
for (int i = 0; i < reps; i++)
printf("%s\n", msg);
}