473,405 Members | 2,167 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,405 software developers and data experts.

Can we use variable length in printf program

151 100+
Hi,
I am working on data formatting. I need to format the data based on input var length by keeping some space. for example.....


void Formater(string str)
{
int len = str.size();
int i = 20;
printf ("%lend", i );
}


in main function call is Formater("Hello");
output should be
' 20' three space before 20.
Here len is variable. but it does not work as expected.How can i implement it. Thanks in advance
Sep 16 '09 #1
1 2162
Banfa
9,065 Expert Mod 8TB
Since you are using string you must be using C++.

Since you are using C++ you should be using cout not printf.

If you were using cout you could use the setw io manipulator to set the width.


As an aside there is a method to pass printf a varible whose contents is used as field width. A quick google should turn it up for you.
Sep 16 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Patrick Dunnigan | last post by:
Hi, I am attempting a bulk copy from a c program into SQL Server 2000 using DBLib in freeTDS 0.63 RC11 (gcc 3.4.3, RH 9). I am getting an error message that I cannot find any documentation on. ...
5
by: dam_fool_2003 | last post by:
Hai, I studied that the array size is fixed. But I come across a word called "variable length array". Is it possible to change the array size? So I tried the following: #include<stdio.h>...
19
by: Skybuck Flying | last post by:
Hi, I think I might have just invented the variable bit cpu :) It works simply like this: Each "data bit" has a "meta data bit". The meta data bit describes if the bit is the ending bit...
8
by: chellappa | last post by:
hi Everybody ! decalaring variable in a.h and using that vaaariable in a1.c and inalization is in main.c it is possible .........pleaase correct that error is it Possible? i am trying it...
4
by: randomtalk | last post by:
hello, I'm doing an exercise in "The C Programming Language, Second Edition". I just can't get one of the first chapter problem correct (I do realize however that there are answer exist on the...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
37
by: Erwin Lindemann | last post by:
If a VLA appears within a loop body, it seems the behavior is different with two different compilers I tried. I looked at the standard text, but couldn't find a definite answer there either. ...
22
by: Tristin.Colby | last post by:
Can someone tell me why giv_len isn't being seen in this statement below "printf("Record %d wrong length:%d Should be %d \n",record,cur_len,giv_len)" =cut #include <stdio.h> #include...
2
by: rameshbabupeddapalli | last post by:
Hi, I want to create my own variable length parameters function it should work like printf() function. When i write the program as given below it's working fine #include<stdio.h> ...
30
by: Adam | last post by:
Hi, I have a simple printf-like function: int print(const char *format, ...) { char buffer; va_list argptr; int i;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.