This C program checks a single character provided as a command-line argument. If the character is 'Y', it prints "satisfied". Otherwise, it prints "not satisfied".
To compile the program, use a C compiler like GCC:
gcc code.c -o code_executable
Run the compiled program with a single character argument:
./code_executable <character>
-
Input 'Y':
./code_executable Y
Output:
satisfied
-
Input any other character (e.g., 'N'):
./code_executable N
Output:
not satisfied
-
Incorrect number of arguments (none or too many):
./code_executable
or
./code_executable A B
Output:
Usage: ./code_executable <character>
The program expects exactly one command-line argument. Only the first character of this argument is processed.
- If the input character is 'Y', the program prints
satisfied
followed by a newline. - If the input character is not 'Y', the program prints
not satisfied
followed by a newline. - If the program is run with an incorrect number of command-line arguments, it prints a usage message:
Usage: ./<program_name> <character>
followed by a newline, and exits with a status code of 1.
The source code is located in code.c
.
#include <stdio.h>
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Usage: %s <character>\n", argv[0]);
return 1; // Indicate an error
}
char c = argv[1][0]; // Get the first character of the first argument
if (c == 'Y') {
printf("satisfied\n");
} else {
printf("not satisfied\n");
}
return 0;
}