Page 153

Write a program that converts upper case to lower or lower case to upper, depending on the name it is invoked with, as found in argv[0].

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char *argv[])
{
	int c;
	while ((c = getchar()) != EOF) {
		if (strcmp(argv[0], "./tolower") == 0) {
			putchar(tolower(c));
		} else if (strcmp(argv[0], "./toupper") == 0) {
			putchar(toupper(c));
		} else {
			putchar(c);
		}
	}
}