473,396 Members | 1,749 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,396 software developers and data experts.

Print Format

Hi,

I want to print a string with defined width left trailed; How can I do
this?

Example: Print ("%05d%3s", &test1, test2[i]);

say test1 = 23
test2[i] = Hi

It prints like 1 2 3 4 5 6 7 8
0 0 0 2 3 H i
But I want like this:
It prints like 1 2 3 4 5 6 7 8
0 0 0 2 3 H i

How can I do this?

Thanks

Feb 9 '06 #1
4 1982
Hello
just use printf("%05d%-3s", &test1, test2[i]);
Greetings Olaf

Feb 9 '06 #2
jo******@yahoo.com wrote:
I want to print a string with defined width left trailed; How can I do
this? Example: Print ("%05d%3s", &test1, test2[i]);
Please note that "printf" is not spelled "Print" and that the '&'
preceding test1 is wrong. say test1 = 23
test2[i] = Hi It prints like 1 2 3 4 5 6 7 8
0 0 0 2 3 H i
But I want like this:
It prints like 1 2 3 4 5 6 7 8
0 0 0 2 3 H i
But neither of those is what it prints, is it?
Those extra spaces may make things clearer to you, but they get in the
way of a clearly stated question.
How can I do this?


#include <stdio.h>

int main(void)
{
char rule[] = "0000000001111111111\n"
"1234567890123456789\n", teststr[] = "Hi";
int testnum = 23;

printf("%s%06d%13s|\n\n", rule, testnum, teststr);
printf("%s%06d%-13s|\n\n", rule, testnum, teststr);
return 0;
}
0000000001111111111
1234567890123456789
000023 Hi|

0000000001111111111
1234567890123456789
000023Hi |

Feb 9 '06 #3

Thanks to All, It works!!!

Feb 13 '06 #4
"PLSQL" <rr*****@gmail.com> writes:
Thanks to All, It works!!!


What worked? Please read <http://cfaj.freeshell.org/google/>.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 13 '06 #5

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

Similar topics

3
by: Paul Watson | last post by:
It is clear that just using 'print' with variable names is relatively uncontrollable. However, I thought that using a format string would reign the problem in and give the desired output. Must...
3
by: DD | last post by:
I have a mainform with a subform. > The main form has a dropdown box "chooseMonth", in the afterupdate event > i requery the subform so all records with the same date are viewed. > Now i only want...
8
by: Eric Lilja | last post by:
As the title, says: Why doesn't the following program print Hi Charles<newline> when run? #include <stdarg.h> #include <stdio.h> static void va_arg_example(const char *format, ...) { va_list...
8
by: Tony | last post by:
Hello I am learning C# and encountered the following problem when I tried to figure out how to print the string {0} in a Console window The following piece of codes complied OK. But when I...
1
by: May | last post by:
is it possible to print a web page by using the PrintDocument class? The thing is that I need to print out some data in a nice format if possible, to a client's default printer. I got the printing...
1
by: Michael Beck | last post by:
I need to select one of about 15 printers, which I have been able to do. Then I need to set that printer as the printer to use, run a Crystal Reports reports, and track if/when the printing job...
4
by: PengYu.UT | last post by:
Suppose I have a dos format text file. The following python code will print ^M at the end. I'm wondering how to print it in unix format. fh = open(options.filename) for line in fh.readlines()...
9
by: cniharral | last post by:
Hi, I'm interested in printing out coloured lines of my application and I don't know what to use. Can anybody give me an idea?? Regards. Carlos Niharra López
4
by: steve | last post by:
When I print to a file using C# print what format is the file written out in? I am debugging a print routine and don't want to do the actual print but would like to open the output file in...
2
by: ravir81 | last post by:
Hi, I am working on excel reporting using Perl. I am facing problem with writing the header part only once for all the excels created using Perl. Here is the code : ...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.