Thread: How do I ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    35

    How do I ...

    How do I get a string to output a letter instead of a vaule in borland???

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    138
    what?

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
    char var = 'A';
    
    printf("%c", var);  //not d
    
    //or
    
    int i;
    char string[] = { "How far to Andromeda?" };
    
    stringLength = strlen(string);
    
    for( i = 0; i < stringLength + 1; i++)
       printf("%c", string[i]);
    Last edited by Adak; 02-06-2009 at 03:44 PM.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    35
    Quote Originally Posted by Adak View Post
    Code:
    char var = 'A';
    
    printf("%c", var);  //not d
    thanks Adak
    so if I wanted to create a program that outputted a letter that the user inputted, would it look like this:
    Code:
    printf ("Please input letter: ");
    int %c
    printf ("The letter you have inputted is: "%c);
    if that is true say I want the user to input a speific letter, would it look like this:
    Code:
    printf ("Please input letter: ");
    int X=A
    int X=B
    
    if X=A printf ("The letter you have inputted is A")
    if X=a printf ("Please input letter in captials") 
    if X=B printf ("The letter you have inputted is A")
    if X=b printf ("Please input letter in captials")
    Last edited by geekrockergal; 02-07-2009 at 04:37 AM.

  5. #5
    Registered User ralu.'s Avatar
    Join Date
    Feb 2009
    Location
    Bucharest, RO
    Posts
    32
    So... if you want to create a program that output a letter that the user inputted you can do smthg like this:

    Code:
    char letter;
    printf ("Please input letter:\n");
    do {
    letter = getch();
    printf ("\nThe letter you have inputted is: ");
    putch(letter);
    }
    while (letter != 27);
    You can do this in many other ways.

  6. #6
    Registered User
    Join Date
    Jan 2009
    Posts
    35
    Quote Originally Posted by ralu. View Post
    So... if you want to create a program that output a letter that the user inputted you can do smthg like this:

    Code:
    char letter;
    printf ("Please input letter:\n");
    do {
    letter = getch();
    printf ("\nThe letter you have inputted is: ");
    putch(letter);
    }
    while (letter != 27);
    You can do this in many other ways.
    thanks whats the != 27 is that something to do with the letter length??

  7. #7
    Registered User
    Join Date
    May 2008
    Location
    Australia
    Posts
    230
    Quote Originally Posted by geekrockergal View Post
    so if I wanted to create a program that outputted a letter that the user inputted, would it look like this:
    Code:
    printf ("Please input letter: ");
    int %c
    printf ("The letter you have inputted is: "%c);
    [/code]
    No, %c basically means printf will attempt to print a character (c for character) and %d means printf will attempt to print a decimal number.

    Code:
    char myCharacter;
    myCharacter = 'A';
    printf("%c", myCharacter);
    That would print "A".
    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    geekrockergal, you need to hit the books or tutorials to understand the basic syntax of C before proceeding.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User ralu.'s Avatar
    Join Date
    Feb 2009
    Location
    Bucharest, RO
    Posts
    32
    Quote Originally Posted by geekrockergal View Post
    thanks whats the != 27 is that something to do with the letter length??
    No. It has nothing to do with the length... 27 is the zecimal value of the ESC ASCII char. So that means do that until "ESC" is pressed.

  10. #10
    Registered User
    Join Date
    Jan 2009
    Posts
    35
    Quote Originally Posted by Elysia View Post
    geekrockergal, you need to hit the books or tutorials to understand the basic syntax of C before proceeding.
    I am Im just writing what Im learning/reading in order to get a better perspective of it
    Im new to C so I make a lot of beginners mistakes !!!
    Thanks to everyone for helping, Im must be really annoying you *bangs head on desk*

  11. #11
    Registered User
    Join Date
    Jan 2009
    Posts
    35
    Quote Originally Posted by ralu. View Post
    No. It has nothing to do with the length... 27 is the zecimal value of the ESC ASCII char. So that means do that until "ESC" is pressed.
    thanks
    Im new to C so I make a lot of beginners mistakes !!!
    Thanks to everyone for helping, Im must be really annoying you *bangs head on desk*

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I see. Well, you have a lot to learn still.
    Good luck with your studies then.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    Jan 2009
    Posts
    35
    Quote Originally Posted by Elysia View Post
    I see. Well, you have a lot to learn still.
    Good luck with your studies then.
    okay thanks
    Im new to C so I make a lot of beginners mistakes !!!
    Thanks to everyone for helping, Im must be really annoying you *bangs head on desk*

  14. #14
    Registered User
    Join Date
    Jan 2009
    Posts
    35
    so is it possiable to do this (I want the user to input a speific character A or B)
    Code:
    char letter;
    printf ("Please input letter:\n");
    if {
    letter = getch(A);
    printf ("\nThe letter you have inputted is: A ");
    putch(letter);
    }
    else{
    letter = getch(a);
    printf ("\nPlease input a captial A ");
    putch(letter);
    }
    if {
    letter = getch(B);
    printf ("\nThe letter you have inputted is: B ");
    putch(letter);
    }
    else{
    letter = getch(b);
    printf ("\nPlease input a captial B ");
    putch(letter);
    }
    Im sorry people I really am trying my hardest to get my head around this
    Im new to C so I make a lot of beginners mistakes !!!
    Thanks to everyone for helping, Im must be really annoying you *bangs head on desk*

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    if {
    If WHAT? If you have an if, then you have then what, too, no?

    getch takes 0 arguments.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed