Hi,
I want to use fprintf to write to a file. My question about the formatted
output
How can I format so that I can allocate certain width for each %s
(Left-aignlied) ?
Example:
fprintf("%s %s %s %s, name, age, city, status);
<-------------------><----------------><----------------><------------->
Benjamin 50 years old New York
Married
Ken 45 years old Los Angelas
Single
Thanks. 6 2990
fprintf("%-s %-s %-s %-s, name, age, city, status);
Left alignes the output
See format specifiers of these. Should be available in one of your C
documents.
- Ravi
"Magix" <ma***@asia.com > wrote in message news:41******** @news.tm.net.my ... Hi,
I want to use fprintf to write to a file. My question about the formatted output How can I format so that I can allocate certain width for each %s (Left-aignlied) ? Example: fprintf("%s %s %s %s, name, age, city, status);
<-------------------><----------------><----------------><-------------> Benjamin 50 years old New York Married Ken 45 years old Los Angelas Single
Thanks.
Hi there,
To show you how it works I give you a code that prints to the standard
output. You can replace stdout with the name of your file. Number 10
indicates the desired width and the negative sign means it's left adjusted.
S is for printing a sequence of chars.
#include <stdio.h>
int main()
{
printf("This is main\n");
fprintf(stdout, "%-10s%-10s\n","Hamed", "Ghorbani" );
}
Sincerely,
Hamed
"Magix" <ma***@asia.com > wrote in message news:41******** @news.tm.net.my ... Hi,
I want to use fprintf to write to a file. My question about the formatted output How can I format so that I can allocate certain width for each %s (Left-aignlied) ? Example: fprintf("%s %s %s %s, name, age, city, status);
<-------------------><----------------><----------------><-------------> Benjamin 50 years old New York Married Ken 45 years old Los Angelas Single
Thanks.
"Hamed" <ha***********@ earthlink.net> wrote in message
news:C5******** ***********@new sread2.news.pas .earthlink.net. .. Hi there, To show you how it works I give you a code that prints to the standard output. You can replace stdout with the name of your file. Number 10 indicates the desired width and the negative sign means it's left
adjusted. S is for printing a sequence of chars. #include <stdio.h> int main() { printf("This is main\n"); fprintf(stdout, "%-10s%-10s\n","Hamed", "Ghorbani" ); } Sincerely, Hamed
"Magix" <ma***@asia.com > wrote in message
news:41******** @news.tm.net.my ... Hi,
I want to use fprintf to write to a file. My question about the
formatted output How can I format so that I can allocate certain width for each %s (Left-aignlied) ? Example: fprintf("%s %s %s %s, name, age, city, status);
<-------------------><----------------><----------------><-------------> Benjamin 50 years old New York Married Ken 45 years old Los Angelas Single
Thanks.
Thank you. Please don't top-post.
"Magix" <ma***@asia.com > wrote in message news:<41******* *@news.tm.net.m y>... Hi,
I want to use fprintf to write to a file. My question about the formatted output How can I format so that I can allocate certain width for each %s (Left-aignlied) ? Example: fprintf("%s %s %s %s, name, age, city, status);
<-------------><-------------><----------><--------> Benjamin 50 years old New York Married
Consult your documentation for fprintf.
fprintf(stdout, "%-15.15s%-15.15s%-12.12s%-10.10s\n",
name, age, city, status);
fprintf(stdout, "%-*.*s%-*.*s%-*.*s%-*.*s\n",
15,15,name, 15,15,age, 12,12,city, 10,10,status);
In article <41**********@n ews.tm.net.my>, ma***@asia.com says... Thank you. Please don't top-post.
Please don't quote an entire article for a one-line response.
--
Randy Howard
To reply, remove FOOBAR.
Hello
To get columns use the format
fprintf(stdout, "==%-10.10s %-10.10s==\n","12 3456789012","12 34");
it breaks the to long string on 10 positions
output will be:
==1234567890 1234 ==
the number 10 can be any number, for more details look in every good C
book.
you get all the details by printf. fprintf, sprintf are just the same
only desternation is different.
greetings Olaf
"Hamed" <ha***********@ earthlink.net> wrote in message news:<C5******* ************@ne wsread2.news.pa s.earthlink.net >... Hi there, To show you how it works I give you a code that prints to the standard output. You can replace stdout with the name of your file. Number 10 indicates the desired width and the negative sign means it's left adjusted. S is for printing a sequence of chars. #include <stdio.h> int main() { printf("This is main\n"); fprintf(stdout, "%-10s%-10s\n","Hamed", "Ghorbani" ); } Sincerely, Hamed
"Magix" <ma***@asia.com > wrote in message news:41******** @news.tm.net.my ... Hi,
I want to use fprintf to write to a file. My question about the formatted output How can I format so that I can allocate certain width for each %s (Left-aignlied) ? Example: fprintf("%s %s %s %s, name, age, city, status);
<-------------------><----------------><----------------><-------------> Benjamin 50 years old New York Married Ken 45 years old Los Angelas Single
Thanks.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Koen |
last post by:
Hi,
could anyone please tell me how I can get the equivalent of this:
fprintf(aFile,"-20.15g",aDouble);
but in C++ using formatted streams?
I tried with C++ formatted streams using:
aStream.width(20);
aStream.precision(15);
but then if there's a very small value, scientific notation is not used
automatically and precision is lost (like in 0.000000000000003 instead
of 3.33333333333e-15).
|
by: Jason Heyes |
last post by:
I am starting to worry about the performance of formatted read/write
operations on data-redundant objects in my program.What can I do to improve
this performance should it become an issue?
Thanks.
|
by: hpy_awad |
last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using
fgets but rabish is being wrote to that file ? Look to my source
please and help me finding the reason why this rabish is being
written.
/* Book name :
File name : E:\programs\cpp\iti01\ch10\ex09_5p1.cpp
Program discription: Adding name,Address to customer_record SETUP
PROGRAM
|
by: G Patel |
last post by:
E. Robert Tisdale wrote:
>
> int main(int argc, char* argv) {
> quad_t m = {0, 1, 2, 3};
> int r;
> fprintf(stdout, "m = (");
> for (size_t j = 0; j < 4; ++j)
Why did you declare j as type size_t ?
|
by: noleander |
last post by:
Sorry if this is a trivial question :-)
I've got several print statements in my code:
fprintf ( stderr, ....);
but when I run my program, I cannot find the output text in any window.
My program is in Visual C++. The program is windows-based (not a
command-line program. The program is not managed. I'm running within the
| |
by: Craig Petrie |
last post by:
Hi,
I have a large table in Word 2003 that has formatted text in the cells and
wish to read and convert a cells formatted contents to html output via
vb.net code. The formatting contains the following: bold text, italic text,
superscript & subscript text, bullet points. The output html is then saved
in an XML file as a CDATA section for later use in the application when
formatted output is required.
I have looked up many sites on the...
|
by: Gary Wessle |
last post by:
Hi
I am trying to pretty print to file 3 vectors (int,double,double)
where all the cells match like a table format where every thing lines
up to the left and space padded to the right.
does c++ has something or mostly use C fprintf?
1255251 0.251025 215.2541
thats how I like it to look, where the space is to the right of the
number and the number left aligns with the field border.
|
by: Prayag Narula |
last post by:
Hi,
I want to redefine fprintf for debugging purposes. That is I want that
all the output that is going to the stdout should be logged in a
file.
I tried something like
#define fprintf (x,y,z) my_fprintf(x,y,z)
|
by: David Mathog |
last post by:
In the beginning (Kernighan & Ritchie 1978) there was fprintf, and unix
write, but no fwrite. That is, no portable C method for writing binary
data, only system calls which were OS specific. At C89 fwrite/fread
were added to the C standard to allow portable binary IO to files. I
wonder though why the choice was made to extend the unix function
write() into a standard C function rather than to extend the existing
standard C function...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |