开发者

converting uppercase to lowercase in C.. (challenging one)

I got this code.. now the challenging part is my prof asked me to make a program which asks the user to input an uppercased word.

The problem is, she wants the program to automatically transform each inputted letter in uppercase even if the user's keyboard is not in capslock mode.. so i don't know what's really wrong with my program... anyone?? help?? i really need it.. thanks..

#include<stdio.h>
#include<ctype.h>
#include<string.h>
typedef char String[100];
main()
{
    char Resp;
    int l, x = 0, asc = 13;
    String s, word1;
    clrscr();
    do {
        printf("\n1st uppercased word: ");
        do {
            s[0] = getch();
            word1[x++] = s[0];
            strupr(s);
            strcat(s, "\0");
            puts(s);
        } while (s[0] != (char) asc);
        strcat(word1, "\0");

        printf("\n\n1st word in lowercase: ");
        for (l = 0; l < strlen(word1); l++)
            putchar(tolower(word1[l]));

        printf("\nDo you want to continue?[Y/N]: ");
        Resp = getche();
    } while (toupper(Resp) == 'Y');

    getch();
    return 0;
}开发者_如何学编程


  1. Get a letter from the user with getch()
  2. Convert it to uppercase with toupper()
  3. Display it with putch()
  4. Go to 1

You may add a break point --- check if the character is the return key and exit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜