C String manipulation/conversion help


 
Thread Tools Search this Thread
Top Forums Programming C String manipulation/conversion help
# 1  
Old 03-12-2005
C String manipulation/conversion help

Hi,

I need to be able to take an unsigned long value and convert it to a string that is separted by commas.

So for example, if i have the unsigned long value 1372516, I'm supposed to somehow get "1,372,516".

Can someone please give me the right direction to go about doing this? Thanks.
# 2  
Old 03-13-2005
This will take some work. You will need to write a little function to handle this kind of thing. As a hint,
printf("i = %d,%3.3d,%3.3d\n",i/1000000, i/1000%1000, i%1000);
would work with the number you posted. But if the number was too small or negative, there would be a problem. A negative number would be a clear problem, but you might want the leading zeros that would happen with small numbers. So you need to decide on your requirements. Do have the possibility of a a negative number? If so how should it be displayed? And so on.
# 3  
Old 03-14-2005
ok thx for ur help. I got it but it took me 4 hours and I believe there's a better way to do it but im busy as it is so dont have time to figure it out. I wrote a really stupid method and basically it's a hack but it works perfectly so I'll just stick with it. Luckily the prof doesn't examine the source code or else I'd lose marks for sure.

Thanks again.
# 4  
Old 03-14-2005
Quote:
Originally Posted by Yifan_Guo
Luckily the prof doesn't examine the source code or else I'd lose marks for sure.
The rules state:
(6) Do not post classroom or homework problems.

I will close this thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting part of a string : string manipulation

i have something like this... echo "teCertificateId" | awk -F'Id' '{ print $1 }' | awk -F'te' '{ print $2 }' Certifica the awk should remove 'te' only if it is present at the start of the string.. anywhere else it should ignore it. expected output is Certificate (7 Replies)
Discussion started by: vivek d r
7 Replies

2. Shell Programming and Scripting

Help With String Manipulation

Hi Guru's, I need some help with data manipulation using shell scripting. I know how to replace the whole string but not part of the string. The value after aa= should be replaced with the value in the mail leaving ,OU=111,OU=222,DC=333 as is. Below are the inputs and expected outputs. Input:... (17 Replies)
Discussion started by: Samingla
17 Replies

3. Shell Programming and Scripting

string manipulation

hi all, i am new to shell scripting and need help. i have a string that stores the month in Jan/Feb/Mar format. i need to convert it to number like 01 for jan, 12 for dec etc. i am using the following sed command, echo "Enter a Month eg. Jan/Feb : " read MONTHEND ... (9 Replies)
Discussion started by: anupom2000
9 Replies

4. Shell Programming and Scripting

string manipulation

if I have two string variable, how do I add one to anther. like a= "a" b="b" c=$a+$b but that doesn't work. Is there anyway to solve it.http://www.qtl.co.il/img/copy.pnghttp://www.google.com/favicon.icohttp://www.babylon.com/favicon.icohttp://www.morfix.com/favicon.ico (2 Replies)
Discussion started by: programAngel
2 Replies

5. Shell Programming and Scripting

String manipulation

Hi, I have the string like this ". Start : 06:53:11 - MON JUL 05, 2010" I need to print the part "06:53:11 - MON JUL 05, 2010" How i can do this? Thanks, Lenova (2 Replies)
Discussion started by: lenova2010
2 Replies

6. Shell Programming and Scripting

String Manipulation

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" (4 Replies)
Discussion started by: proactiveaditya
4 Replies

7. Shell Programming and Scripting

string manipulation

Hi all, see i have a script that takes few arguments. first one is command we do on file, next is file (mostly txt file with lot of data) third is destination where we do something with data in file. Since im new in scripting, and im learning as i go, i need some hint how to manipulate that... (3 Replies)
Discussion started by: ajemrunner
3 Replies

8. UNIX for Dummies Questions & Answers

string manipulation

Hi, I have a file with rows of text like so : E100005568374098100000015667 D100005568374032000000112682 H100005228374060800000002430 I need to grab just the last digits(bolded) of each line without the proceeding text/numbers. Thanks (5 Replies)
Discussion started by: james6
5 Replies

9. Shell Programming and Scripting

string manipulation

Hello, I have a korn shell string variable str1 = "A,B,Z" I would like to create another korn shell string variable str2 = "letter = 'A' or letter = 'B' or letter = 'Z' " Please help! Thanks in advance an UNIX newbie! (13 Replies)
Discussion started by: hai1973
13 Replies

10. Shell Programming and Scripting

String Manipulation

Hi, Suppose I have the following text in a file. ORA-00942: table or view does not exist ORA-01555: snapshot too old: rollback segment number string with name "string" too small Is there any way I can list all the text that starts only with 'ORA-'? Or there any grep command that can... (7 Replies)
Discussion started by: kakashi_jet
7 Replies
Login or Register to Ask a Question