a big problem

Discussion in 'C Programming' started by ash, Dec 25, 2005.

  1. ash

    ash Guest

    there is a question:

    write a program which when executed would keep coverting every capital
    letter on the screen to small case letter and every small case letter
    to capital letter.The procedure should stop the movement the user hits
    a key from keyboard.

    I had "Let us C" book and this question on page 278, I m trying my best
    but unable to do till now, any one knows what to do.
    thankx and genious i will say who will do it
    ash, Dec 25, 2005
    #1
    1. Advertising

  2. ash wrote:
    > there is a question:
    >
    > write a program which when executed would keep coverting every capital
    > letter on the screen to small case letter and every small case letter
    > to capital letter.The procedure should stop the movement the user hits
    > a key from keyboard.


    It is not a question, it is a homework...

    > I had "Let us C" book and this question on page 278, I m trying my best
    > but unable to do till now, any one knows what to do.
    > thankx and genious i will say who will do it


    Show us the best you did and someone will guide you...
    Giannis Papadopoulos, Dec 25, 2005
    #2
    1. Advertising

  3. ash

    ash Guest

    ok
    there is some code

    #include<stdio.h>
    #include<dos.h>

    main()
    {
    char far *scr=0xB8000000;
    int i
    while(!kbhit())
    {
    for(i=0;i<=3999;i+=2)
    if(scr>='A' &7 scr<='Z')
    {
    scr+=32;
    }
    else
    {
    if(scr>='a'&&scr<='z')
    {
    scr-=32;
    }}
    }}

    this is its answer but when i run this program nothing happened i have
    turbo C++ 3.1
    i was not trying to convience for doing my homework my friends
    ash, Dec 25, 2005
    #3
  4. ash

    Guest

    Turbo C++ 3.1, Oh, an IDE which has been out of the day yet.
    Hmm, you've made some literal mistakes, I marked them after "//"

    #include<stdio.h>
    #include<dos.h>


    main()
    {
    char far *scr=0xB8000000; //the compile message show "warning"
    int i // semicolon missed
    while(!kbhit()) // it can make the exe file trap in dead recycling
    {
    for(i=0;i<=3999;i+=2)
    if(scr>='A' &7 scr<='Z') // the digit 7 should be delete
    {
    scr+=32;
    }
    else
    {
    if(scr>='a'&&scr<='z')
    {
    scr-=32;
    }}
    }}

    Although I compiled it succeefully, it's not a normal program. And I
    will examine it later.
    , Dec 25, 2005
    #4
  5. ash

    pemo Guest

    "ash" <> wrote in message
    news:...
    > ok
    > there is some code
    >
    > #include<stdio.h>
    > #include<dos.h>
    >
    > main()
    > {
    > char far *scr=0xB8000000;
    > int i
    > while(!kbhit())
    > {
    > for(i=0;i<=3999;i+=2)
    > if(scr>='A' &7 scr<='Z')
    > {
    > scr+=32;
    > }
    > else
    > {
    > if(scr>='a'&&scr<='z')
    > {
    > scr-=32;
    > }}
    > }}
    >
    > this is its answer but when i run this program nothing happened i have
    > turbo C++ 3.1
    > i was not trying to convience for doing my homework my friends


    You're trying to access VGA [colour] memory in 'text mode' as far as I can
    tell (plus there's no ';' after int i and &7 should be &&, 'far' is
    obselete).

    Is this an old book?
    pemo, Dec 25, 2005
    #5
  6. ash

    ash Guest

    yes plz suggest me
    i wanna master in c
    what compiler should i use
    help me
    ash, Dec 25, 2005
    #6
  7. ash

    ash Guest

    sorry it was my typing mistake but the main problem remains there.Plz
    read the question carefully then give me a right answer
    ash, Dec 25, 2005
    #7
  8. ash

    ash Guest

    sorry it was my typing mistake but the main problem remains there.Plz
    read the question carefully then give me a right answer
    ash, Dec 25, 2005
    #8
  9. ash

    Guest

    How about this?

    #include<stdio.h>

    int main()
    {
    char scr;

    printf("input the character: ");
    scanf("%s", &scr);

    if (scr >= 'A' && scr <= 'Z')
    {
    scr += 32;
    }
    if (scr >= 'a'&& scr <= 'z')
    {
    scr -= 32;
    }

    printf("the result is: %s", &scr);

    return 0;
    }

    Simple code is ok, i think.
    The IDE I used is Dev-C++ 4.9.9.0.
    , Dec 25, 2005
    #9
  10. ash

    ash Guest

    write a program which when executed would keep coverting every capital
    letter on the screen to small case letter and every small case letter
    to capital letter.The procedure should stop the movement the user hits
    a key from keyboard.

    this is my problem.
    your solution will won`t work my friend but nice try
    ash, Dec 25, 2005
    #10
  11. ash

    ash Guest

    write a program which when executed would keep coverting every capital
    letter on the screen to small case letter and every small case letter
    to capital letter.The procedure should stop the movement the user hits
    a key from keyboard.

    this is my problem.
    your solution will won`t work my friend but nice try
    ash, Dec 25, 2005
    #11
  12. ash

    David Bolt Guest

    On Sun, 25 Dec 2005, ash <> wrote:-

    >sorry it was my typing mistake but the main problem remains there.Plz
    >read the question carefully then give me a right answer


    This is pseudo-code but it might do:

    /*
    you might need to adjust these
    */
    #include <stdio.h>
    #include <dos.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>

    main()
    {
    char far *scr=0xb8000000;
    int offset=0;

    while(!kbhit())
    {
    for(offset=0;offset<4000;offset+=2)
    {
    if(isalpha(scr[offset])) /* check the character is a letter */
    {
    if(isupper(scr[offset])) /* is it upper case? */
    {
    scr[offset]=tolower(scr[offset]); /* yes. Convert to lower case */
    }
    else
    {
    scr[offset]=toupper(scr[offset]); /* no. convert to upper case */
    }
    }
    }
    }
    exit 0;
    }

    You could also replace:

    if(isalpha(scr[offset])) /* check the character is a letter */
    {
    if(isupper(scr[offset])) /* is it upper case? */
    {
    scr[offset]=tolower(scr[offset]); /* yes. Convert to lower case */
    }
    else
    {
    scr[offset]=toupper(scr[offset]); /* no. convert to upper case */
    }
    }

    with:

    if(isalpha(scr[offset])) /* check the character is a letter */
    {
    scr[offset]^=32;
    }

    Unfortunately, I don't have access to an old DOS compiler to test the
    above but it should work, possibly after a little tweaking.


    Regards,
    David Bolt

    --
    Member of Team Acorn checking nodes at 50 Mnodes/s: http://www.distributed.net/
    AMD1800 1Gb WinXP/SUSE 9.3 | AMD2400 256Mb SuSE 9.0 | A3010 4Mb RISCOS 3.11
    AMD2400(32) 768Mb SUSE 10.0 | RPC600 129Mb RISCOS 3.6 | Falcon 14Mb TOS 4.02
    AMD2600(64) 512Mb SUSE 10.0 | A4000 4Mb RISCOS 3.11 | STE 4Mb TOS 1.62
    David Bolt, Dec 25, 2005
    #12
  13. ash a écrit :
    > ok
    > there is some code
    >
    > #include<stdio.h>
    > #include<dos.h>


    starts badly...

    > main()
    > {
    > char far *scr=0xB8000000;


    WTF! How is this old PC/MS-DOS hack ralated with you question ?

    If you are learning C, please stick to the standard and portable code.
    BTW, don't waiste your time with obsolet hacks suposed to work on
    machines with a lousy OS...

    Modern OS'es don't support this kind of abobination and will kill such a
    devilish process..

    Try this :

    http://publications.gbdirect.co.uk/c_book/

    --
    A+

    Emmanuel Delahaye
    Emmanuel Delahaye, Dec 25, 2005
    #13
  14. a écrit :

    > if (scr >= 'A' && scr <= 'Z')


    Not portable hack. Works fine with ASCII but neither with extended ISO
    characters (iso-8859-1), nor with EBCDIC for example.

    --
    A+

    Emmanuel Delahaye
    Emmanuel Delahaye, Dec 25, 2005
    #14
  15. "ash" <> writes:
    > there is a question:
    >
    > write a program which when executed would keep coverting every capital
    > letter on the screen to small case letter and every small case letter
    > to capital letter.The procedure should stop the movement the user hits
    > a key from keyboard.
    >
    > I had "Let us C" book and this question on page 278, I m trying my best
    > but unable to do till now, any one knows what to do.
    > thankx and genious i will say who will do it


    Standard C provides no way to retrieve characters on the screen. On
    many systems, there's no portable way to do this unless you've kept
    track of what you've written to the screen yourself.

    Standard C provides no way to interrupt a program when a key is
    pressed. If you try to read a character from stdin, the program will
    block until the user enters a newline.

    Try a newsgroup that deals with whatever system you're using.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Dec 25, 2005
    #15
  16. ash a écrit :
    > yes plz suggest me
    > i wanna master in c
    > what compiler should i use


    Please check your spelling. English is not my native language, and I
    have hard time trying to decode your langage...

    I guess that your platform is a PC with a 32-bit Windows. You can try
    Code::Blocks.

    http://www.codeblocks.org/

    --
    A+

    Emmanuel Delahaye
    Emmanuel Delahaye, Dec 25, 2005
    #16
  17. ash

    Malcolm Guest

    "ash" <> wrote
    > write a program which when executed would keep coverting every capital
    > letter on the screen to small case letter and every small case letter
    > to capital letter.The procedure should stop the movement the user hits
    > a key from keyboard.
    >
    > I had "Let us C" book and this question on page 278, I m trying my best
    > but unable to do till now, any one knows what to do.
    > thankx and genious i will say who will do it
    >

    The logic is trivial - just call toupper() and tolower() to convert the
    characters.

    The hard part is addressing the screen. Virtually all C compilers come with
    some sort of non-standard library for accessing character-mapped screens.
    Under Unix it will usually be called "curses" whilst under DOS you include a
    (non-standard) header called "conio.h".
    Look up the function in these and try to use them. Unfortunately the details
    are not on topic here.
    Malcolm, Dec 25, 2005
    #17
  18. ash

    Guest

    Emmanuel Delahaye wrote:
    > a écrit :
    >
    > > if (scr >= 'A' && scr <= 'Z')

    >
    > Not portable hack. Works fine with ASCII but neither with extended ISO
    > characters (iso-8859-1), nor with EBCDIC for example.
    >


    This will work with EBCDIC. It will even work, amazingly, with Baudot.
    In fact, it will even work with Morse code. When designing character
    sets, humans have a tendency to make A-Z contiguous. (Of course, for
    Baudot and Morse A-Z exists but there are no a-z).
    , Dec 25, 2005
    #18
  19. ash

    Guest

    ash wrote:
    > ok
    > there is some code
    >
    > #include<stdio.h>
    > #include<dos.h>
    >
    > main()
    > {
    > char far *scr=0xB8000000;
    > int i
    > while(!kbhit())
    > {
    > for(i=0;i<=3999;i+=2)
    > if(scr>='A' &7 scr<='Z')
    > {
    > scr+=32;
    > }
    > else
    > {
    > if(scr>='a'&&scr<='z')
    > {
    > scr-=32;
    > }}
    > }}
    >
    > this is its answer but when i run this program nothing happened i have
    > turbo C++ 3.1
    > i was not trying to convience for doing my homework my friends


    This is not C programming, it's DOS programming. The language used may
    be C but the question posed have little to do with C (in fact,
    impossible to do with C without additional help, form your OS or the
    BIOS or your graphic card) but more to do with DOS and the Intel x86
    platform.

    This does illustrate the power of C - that you can do very low level
    assembly-like programs and directly access hardware without any API or
    device drivers (depends on your OS, try this on UNIX and you'll fail).
    But again, it is more to do with how to write assembly-like programs in
    C rather than how to write a C program.
    , Dec 25, 2005
    #19
  20. ash

    Joe Wright Guest

    wrote:
    > Emmanuel Delahaye wrote:
    >
    >> a écrit :
    >>
    >>
    >>>if (scr >= 'A' && scr <= 'Z')

    >>
    >>Not portable hack. Works fine with ASCII but neither with extended ISO
    >>characters (iso-8859-1), nor with EBCDIC for example.
    >>

    >
    >
    > This will work with EBCDIC. It will even work, amazingly, with Baudot.
    > In fact, it will even work with Morse code. When designing character
    > sets, humans have a tendency to make A-Z contiguous. (Of course, for
    > Baudot and Morse A-Z exists but there are no a-z).
    >

    No. A-Z are not contiguous in EBCDIC. Baudot? Morse code doesn't have a
    binary representation that I know of. What are you talking about?

    --
    Joe Wright
    "Everything should be made as simple as possible, but not simpler."
    --- Albert Einstein ---
    Joe Wright, Dec 26, 2005
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    11
    Views:
    689
    Roedy Green
    Sep 18, 2005
  2. Shaguf
    Replies:
    0
    Views:
    318
    Shaguf
    Dec 24, 2008
  3. Shaguf
    Replies:
    0
    Views:
    422
    Shaguf
    Dec 26, 2008
  4. Shaguf
    Replies:
    0
    Views:
    207
    Shaguf
    Dec 26, 2008
  5. Shaguf
    Replies:
    0
    Views:
    193
    Shaguf
    Dec 24, 2008
Loading...

Share This Page