Hi everyone
I have a database of 24 tables all with 'dot separated numbers like 39.6' and I am extracted the required data in to one table which is also a dot separated data. But I need that data in comma separated value"i.e. in place of 39.6 i need 39,6"..Since I am in Germany here comma's and dot's are replaced. So can you give me a code so that if there are any dots in my input it should be converted to comma and should give it in my out put.
Thank you
12 1582
You can use sscanf() and sprintf(), something like this: -
char num[] = "39.6";
-
int p,d;
-
sscanf(num,"%i.%i",p,d); // p=39 and d=6
-
sprintf(num,"%i,%i",p,d); // now num = "36,6"
-
donbock 2,426
Recognized Expert Top Contributor
Another option is to investigate how locales work. I've never used this feature myself, but my understanding is that if you set the right locale then the numbers will naturally print out with commas instead of periods.
can you tell me what a locale is...I have never heard of it and can you tell me how can I check that for solving this problem..
Thank you
You can use sscanf() and sprintf(), something like this: -
char num[] = "39.6";
-
int p,d;
-
sscanf(num,"%i.%i",p,d); // p=39 and d=6
-
sprintf(num,"%i,%i",p,d); // now num = "36,6"
-
Thank you.....I have got the output with the above code...but with some changes....
can you tell me what a locale is...I have never heard of it and can you tell me how can I check that for solving this problem..
Thank you
donbock is right - locales are the best way to solve your problem. I've used it before in a project that had to support multiple languages and numerical formats (like what you want to do with , and . )
Have a look at these links - I just googled them up but they should give you an idea. http://www.w3.org/International/questions/qa-i18n http://www.acm.uiuc.edu/webmonkeys/b...guide/2.6.html JosAH 11,448
Recognized Expert MVP
Another option is to investigate how locales work. I've never used this feature myself, but my understanding is that if you set the right locale then the numbers will naturally print out with commas instead of periods.
In an ideal world that would work; in a real world most of the time just the "C"
locale is supported which prints the decimal point as a dot. The solution given
above will work or otherwise the following little hack will do: -
char* replaceXbyY(char* p, char x, char y) {
-
char* s;
-
for (s= p; s && *s; s++)
-
if (*s == x) *s= y;
-
return p;
-
}
-
kind regards,
Jos
In an ideal world that would work; in a real world most of the time just the "C"
locale is supported which prints the decimal point as a dot. The solution given
above will work or otherwise the following little hack will do: -
char* replaceXbyY(char* p, char x, char y) {
-
char* s;
-
for (s= p; s && *s; s++)
-
if (*s == x) *s= y;
-
return p;
-
}
-
kind regards,
Jos
Hi...
Can you give me a code for this in for loop 'like' in the for loop it should check all my data and if it is a point that point should be replaced by a comma
JosAH 11,448
Recognized Expert MVP
Hi...
Can you give me a code for this in for loop 'like' in the for loop it should check all my data and if it is a point that point should be replaced by a comma
No; the little 'replaceXbyY' function replaces all 'x's by 'y's in a string; I leave it
to your imagination how to use it for your output.
kind regards,
Jos
So, In place of X and Y can we keep '.' and ','. By initializing dot to X and Comma to Y.
JosAH 11,448
Recognized Expert MVP
So, In place of X and Y can we keep '.' and ','. By initializing dot to X and Comma to Y.
Sure; have a look at the parameter list: x and y are parameters and the function
replaces the value of every x by the value of y. Feel free to change that little
function.
kind regards,
Jos
I didn't understand the for loop in the given program....Can you explain it for me....
Regards
Siva
JosAH 11,448
Recognized Expert MVP
I didn't understand the for loop in the given program....Can you explain it for me....
Either parameter p is NULL or it isn't. If it is the condition 's && *s' fails immediately
and no loop body is executed. Otherwise pointer s traverses over all characters
pointed to by p and s until it reaches the '\0' character in which case the for loop
condition 's && *s' fails again.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jn |
last post by:
I have a link that must have a GET variable with spaces in it. PHP keeps
inserting the session id right in the middle of my links. I've tried
replacing all spaces with %20...it still sticks it in...
|
by: Sorby |
last post by:
Hi
I've been coding in PHP for a little while now and was starting to feel
pretty confident but then realise I need to understand regular expressions
to solve a particular problem I've got ......
|
by: yaipa |
last post by:
What would be the common sense way of finding a binary pattern in a
..bin file, say some 200 bytes, and replacing it with an updated pattern
of the same length at the same offset?
Also, the...
|
by: VMI |
last post by:
If I have the string "Héllo", how can I replace char (é) with an 'e'? I
cannot use the String.Replace() fuction. It has to be by replacing one char
with another.
Thanks.
|
by: WT |
last post by:
Hello,
I was using hastable to store collection of objects of the same class
MyClass.
I start replacing this hastable by a Dictionary<string,MyClass>....but
I was storing this hastable in cache...
| |
by: saif.shakeel |
last post by:
Hi,
I need to replace a string in xml file with something else.Ex
- <SERVICEPARAMETER id="_775" Semantics="subfunction" DDORef="_54">
<SHORTNAME>rate</SHORTNAME>
<LONGNAME>rate</LONGNAME>...
|
by: patelgaurav85 |
last post by:
Hi,
I want to convert xml in one format into another xml format shown below
Input xml :
<Name>
<Name1>
<Name11>Name11</Name11>
<Name12>Name12</Name12>
|
by: Matt Herzog |
last post by:
Hey All.
I'm learning some python with the seemingly simple task of updating a firewall config file with the new IP address when my dhcpd server hands one out. Yeah, I know it's dangerous to edit...
|
by: gskbond |
last post by:
I have a template file whose line reads as:
CREATE TABLESPACE "CUSTTBS" LOGGING DATAFILE '{DBFILE_PATH}cust.dbf' SIZE 1000M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| | |