Thread: Problem with inserting Character.

  1. #1
    Registered User
    Join Date
    Nov 2009
    Location
    London UK
    Posts
    3

    Problem with inserting Character.

    Hi all, I'm new to C programming so be gentle with me.

    I have had some assignment work to do. On this i have finished the code and everything works, so dont worry im not asking for the solution because of student type lazyness!

    I have one line in my code
    Code:
    printf("Please insert the value in £: ");
    I want the output text to read "Please insert the value in £", but when i run what is contained in that line it converts the £ into u-hat...on either side of the colon. There seems to be nothing on this on searching my c books or the interweb. I would prefer to keep this simple'ish if there is a way of doing it.

    Question - Is there a simpler method of inserting £ so that the user knows which currency to be inserting.

    Thanks in advance!

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    It depends on what your char set is set up to handle. Try this:

    Code:
    printf("\n Please insert the value in %c: ",  156);

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Use the Unicode codepoint for it, i.e.
    Code:
    printf("\u00A3\n");

  4. #4
    Registered User
    Join Date
    Nov 2009
    Location
    London UK
    Posts
    3
    Quote Originally Posted by Adak View Post
    It depends on what your char set is set up to handle. Try this:

    Code:
    printf("\n Please insert the value in %c: ",  156);
    That did the trick, many thanks! Where do you get the 156 from? Is this an Extended ASCII table or from somewhere else?

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    75
    Quote Originally Posted by Caerleon View Post
    That did the trick, many thanks! Where do you get the 156 from? Is this an Extended ASCII table or from somewhere else?
    nadroj suggestion was better.

  6. #6

  7. #7
    Registered User
    Join Date
    Nov 2009
    Location
    London UK
    Posts
    3
    Quote Originally Posted by MisterIO View Post
    nadroj suggestion was better.
    I tried both solutions, but was looking for a simpler method as my professor needs to read the source code aswell as see the output.

    With the second suggestion i dont think i put it in the proper place as it errored, so i used the first suggested method. Thanks anyway.

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Your highest probability of success - for reasons listed in the link I provided - is the following:
    Code:
    #include <stdio.h>
    #include <locale.h>
    
    const wchar_t pound = L'\u00a3';
    
    int main()
    {
        setlocale(LC_ALL, "");
        printf("pound = %lc\n", pound);
        return 0;
    }
    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem about Character Constant of \t
    By userpingz in forum C++ Programming
    Replies: 3
    Last Post: 06-24-2009, 03:30 AM
  2. C language and NULL character problem
    By ndru_w in forum C Programming
    Replies: 4
    Last Post: 11-23-2007, 09:42 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Problem with character arrays in classes
    By spoketoosoon in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2004, 03:57 AM
  5. Comparing Character Arrays problem...
    By newy100 in forum C++ Programming
    Replies: 4
    Last Post: 11-16-2003, 07:54 PM