Solved

How do I manipulate integers as characters

Posted on 1998-12-11
1
195 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

685 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