473,378 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

printf: Centre justify data

Hi all,
Is there any way to print the data in the center of the field width? I
have searched in internet and I got code for center justifying string
data. But I need to center other data types too. At least give me some
hint to do this if not the exact code.

Dec 2 '05 #1
2 7288
>Is there any way to print the data in the center of the field width? I
have searched in internet and I got code for center justifying string
data. But I need to center other data types too. At least give me some
hint to do this if not the exact code.


You have a field width W. You have a string of width S. You need
W-S padding spaces (if it's negative, you're in trouble!). Put
L=(W-S)/2 padding spaces on the left, and R=(W-S)-L padding spaces
on the right.

If you need to center other data types, well, sprintf() returns
the length of the string it's going to generate. If you have
snprintf() available (C99, not C89) you might consider using it.

Gordon L. Burditt
Dec 2 '05 #2
va******@rediffmail.com wrote:
Hi all,
Is there any way to print the data in the center of the field width? I
have searched in internet and I got code for center justifying string
data.
Good.
But I need to center other data types too. At least give me some
hint to do this if not the exact code.


All other data types can be converted to string data using sprintf().
Once this is done use the code you got for center justifying strings.

Dec 2 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tony Murphy | last post by:
I've got an application that sends emails (not spam!). The application reads a template file (html/text) into a string, the string is processed and placeholders filled in as appropiate. I call a...
2
by: jwatts | last post by:
Hello group, I am feeling pretty good about this program. I am just learning and am trying to get the basics down. I would like to ask if someone could tell me how to right justify the BALANCE...
4
by: Dan | last post by:
I'm trying to creat a data structure, that can be either a integer, double, string, or linked list. So I created the following, but don't know if it is the data structure itself causing problems,...
5
by: Kutty Banerjee | last post by:
hi , i ve int (*Data); int A={1,2,3,4}; Data=&A; //Question here, how d i dynamically allocate space for Data using calloc? printf("%d\n",*Data) ; //gives 1 //But printf("%d\n",*Data)...
3
by: Hans Ginzel | last post by:
Hello, let us consider function int foo(char *name, void *data) { ... printf(name, data); /* Should be *data? */ ... }
3
by: pecan | last post by:
I've been trying to justify some text: when I align it left or right or centre, it works, but when I align it to justify it ignores me. I've tried overriding the CSS by justifying withing the html...
2
by: triphoppa | last post by:
Ok, I'm trying to read in some integers from a file for some reason however my array is not filling up. I know it's not filling up because I can watch the array in the debugger. My code looks...
1
by: Tracey Marshall | last post by:
The program is designed to collect and print data from user. It loops through the options. The user can input data, print the data to screen and then choose to input data again adding to the...
1
kirubagari
by: kirubagari | last post by:
Im having issue whereby i have to filter out the data and stored in abnormal log file.my code as below and i have attach the file to give the clearer picture of the scenario.I need to filter the data...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.