Solved

How do I manipulate integers as characters

Posted on 1998-12-11
1
192 Views
Last Modified: 2010-04-15
I have a little code that converts seconds to days, hours, minutes, and seconds.  I want to create one string variable of the form "days:hours:min:sec", but I am having no luck using the strcat function because my variables are integers.
0
Comment
Question by:jshirer
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 total points
ID: 1255054
int days = 1 ;
int hours = 2 ;
int mins = 3 ;
int sec = 4 ;

char ss[256] ;
sprintf( ss, "%d days %d:%d:%d", days, hours, mins, sec ) ;

%d means the string will contain an integer parameter.

%2d (or another number) means integer parameter width is 2 characters

%02d (or another number) means pad integer parameter to 2 characters with leading zeroes
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now