Solved

How do I manipulate integers as characters

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

747 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

12 Experts available now in Live!

Get 1:1 Help Now