Solved

How do I manipulate integers as characters

Posted on 1998-12-11
1
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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

Suggested Solutions

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
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.
Suggested Courses

734 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