Страницы

Translate

вторник, 12 ноября 2013 г.

Exercise 7.1. Write a program that converts upper case to lower or lower case to upper



Exercise 7.1. 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].

I changed a little exercise , I think it would be better.

 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[1].


#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
    int c;
   
    if(argc != 2)
    {
        printf("ERROR, no parametrs\n");
        return 1;
    }
    else if(strcmp(argv[1], "lower") == 0)
        while((c = getchar()) != EOF)
            putchar(tolower(c));
    else if(strcmp(argv[1], "upper") == 0)
        while((c = getchar()) != EOF)
            putchar(toupper(c));
    else
        printf("wrong parametrs\n");
    return 0;
}

 

Комментариев нет:

Отправить комментарий