Thread: beginner question

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    7

    Question beginner question

    Hi,

    I would like to print the ascII value of the letter p using the variable Mychar. Using a printf() statement is this the correct format.


    char MyChar;
    MyChar ='p';

    printf("The value of %c in octal is %#0\n",'MyChar');


    thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No. Don't put your variable name in single quotes.

    printf("%c is %d", MyVar, MyVar );

    Read up on printf and its format specifiers.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    you coulda cut out the variable by just directly putting 'p' as the 2nd param of printf. 'MyVar' and MyVar are two different things. 'MyVar' is illegal, but you might have meant "MyVar" which is a string. MyVar is a variable/constant with meaning.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner: Linked List question
    By WeatherMan in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2008, 07:16 AM
  2. Quick IF statement question (beginner)
    By jim.rattlehead in forum C Programming
    Replies: 23
    Last Post: 11-29-2007, 06:51 AM
  3. beginner question
    By Barrot in forum C++ Programming
    Replies: 4
    Last Post: 08-19-2005, 02:17 PM
  4. Question About External Files (Beginner)
    By jamez05 in forum C Programming
    Replies: 0
    Last Post: 08-11-2005, 07:05 AM
  5. Beginner on Win32 apps, lame question.
    By Templario in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 08:39 PM