|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/cs256su21code/jul06/strcmp.c
/*
demonstrating strcmp
strcmp is a function that compares two strings
int rt = strcmp(str1, str2);
if rt < 0, then str1 is "less" than str2
if rt == 0, then str1 is the same as str2
if rt > 0, then str1 is "greater" than str2
In this context, when we say "less" and "greater", we mean the ascii values of the
non-matching characters of the two strings.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]){
if(argc < 2){
printf("Usage: %s something\n", argv[0]);
exit(1);
}
if(strcmp(argv[1], "dog") == 0){
printf("you entered the word dog\n");
} else {
printf("you did not enter the word dog\n");
}
return 0;
}
|