C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-04-2009, 09:19 AM   #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!
Caerleon is offline   Reply With Quote
Old 11-04-2009, 10:58 AM   #2
Registered User
 
Join Date: Sep 2006
Posts: 2,517
It depends on what your char set is set up to handle. Try this:

Code:
printf("\n Please insert the value in %c: ",  156);
Adak is offline   Reply With Quote
Old 11-04-2009, 11:01 AM   #3
Registered User
 
Join Date: Oct 2006
Location: Canada
Posts: 848
Use the Unicode codepoint for it, i.e.
Code:
printf("\u00A3\n");
nadroj is offline   Reply With Quote
Old 11-04-2009, 02:58 PM   #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?
Caerleon is offline   Reply With Quote
Old 11-04-2009, 03:40 PM   #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.
MisterIO is offline   Reply With Quote
Old 11-04-2009, 04:22 PM   #6
Registered User
 
Codeplug's Avatar
 
Join Date: Mar 2003
Posts: 3,844
Relevant discussion: how do i printf("®") to the console?

gg
Codeplug is offline   Reply With Quote
Old 11-13-2009, 04:59 AM   #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.
Caerleon is offline   Reply With Quote
Old 11-13-2009, 07:39 AM   #8
Registered User
 
Codeplug's Avatar
 
Join Date: Mar 2003
Posts: 3,844
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
Codeplug is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 03:44 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22