473,396 Members | 2,018 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.

Help needed with line-feed

I am 'dabling' with a piece of code:

int k;
for(k = 1; k < 6; k++)
{
printf("%3d\f", k)
}
with the expectation that the output would be something like:
1
2
3 etc
instead I get:
1
2
3
etc
ie the \f is being treated as \n
Any ideas please?
John Ferguson

Nov 14 '05 #1
4 1545
In article <20***************************@mb-m04.aol.com>,
Jrferguson <jr********@aol.com> wrote:
: printf("%3d\f", k)

:with the expectation that the output would be something like:
: 1
: 2

:ie the \f is being treated as \n

The C89 standard says

\f (form feed) Moves the active position to the start of the
next logical page
However, the meaning of "logical page" is implimentation dependant
and possibly hardware dependant (terminal emulation software at least),
so the behaviour you see is not inconsistant with the C standards.

if you need the behaviour you were expecting, you should probably use
a package such as curses.
--
Scintillate, scintillate, globule vivific
Fain would I fathom thy nature specific.
Loftily poised on ether capacious
Strongly resembling a gem carbonaceous. -- Anon
Nov 14 '05 #2
Jrferguson wrote:
I am 'dabling' with a piece of code:

int k;
for(k = 1; k < 6; k++)
{
printf("%3d\f", k)
}
with the expectation that the output would be something like:
1
2
3 etc
instead I get:
1
2
3
etc
ie the \f is being treated as \n
Any ideas please?


'\f' -- form feed.
If you want to position the numbers abusing the field width of
the printf() format, then consider
int k;
for(k = 1; k < 6; k++)
{
printf("%*d\n", 3*k, k)
}
I do not recommend this, though.
If you want more console magic or free "positioning", then you
are leaving the scope of standard C.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 14 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jrferguson wrote:
I am 'dabling' with a piece of code:

int k;
for(k = 1; k < 6; k++)
{
printf("%3d\f", k)
}
with the expectation that the output would be something like:
1
2
3 etc
instead I get:
1
2
3
etc
ie the \f is being treated as \n
According to my sources, "\f" "moves the active position to the initial
position at the start of the next logical page."

Apparently, your logical page is one line long.

As for the left alignment, "initial position" usually means the leftmost
position (in a left-to-right presentation media).
Any ideas please?
John Ferguson

- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFCCSgeagVFX4UWr64RArUJAJ9P1qeJC3wi07LZX+Fmh2 fem2D4iACcDrgQ
gbQJ426p4dfwsmgF/frZBqg=
=ZHhA
-----END PGP SIGNATURE-----
Nov 14 '05 #4
Jrferguson wrote:
I am 'dabling' with a piece of code:

for(int k = 1; k < 6; ++k) {
printf("%3d\f", k)
}

with the expectation that the output would be something like:
1
2
3 etc
instead I get:
1
2
3
etc
i.e. the \f is being treated as \n
No. '\f' is formfeed not linefeed.
If you redirect output to a printer,
you will get 6 pages of output
with a single digit in the upper left hand corner of each page.
Any ideas please?


UNIX operating systems interpret linefeed '\n'
as the carriage return '\r' line feed '\n' sequence on Windows
so you can't get just a linefeed.
Nov 14 '05 #5

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

Similar topics

4
by: pekka niiranen | last post by:
Hi there, I have perl script that uses dynamically constructed regular in this way: ------perl code starts ---- $result ""; $key = AAA\?01; $key = quotemeta $key; $line = " ...
31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
8
by: rh0dium | last post by:
Hi all, I am using python to drive another tool using pexpect. The values which I get back I would like to automatically put into a list if there is more than one return value. They provide me...
8
by: Artemio | last post by:
Dear folks, I need some help with using the sscanf() function. I need to parse a string which has several parameters given in a "A=... B=... C=..." way, and each has a different type (one is a...
3
by: Kitana907 | last post by:
Hi- I'm attempting to write a module that uses and updates info from two tables and does the following: Opens the recordset of a table called "tblstoreinv" If the Needed Field in the...
10
by: B. Williams | last post by:
I have an assignment that requires me to write a program that uses a class, a constructor, a switch, and store the records in a text file. The second requirement is to create a function called...
1
by: teddymeu | last post by:
hi guys I posted the other day regarding a solution i needed to design, im new to development an asp,net and built a local post office search tool using asp.net 2. vb in visual studio, using an...
1
by: kpm5589 | last post by:
I needed some help in the following code line 50 - char *b, q, *r; line 200 - b = getbuf (); Line 201 q = *b; Line 212 R = anotherfunction (b); Lines 213-2003 /* we want to use 'q' and 'r'...
1
by: janakivenk | last post by:
Hello, I am running Oracle 10g R2 in our office. I created the following procedure. It is suppose to access an xml file ( family.xml). The procedure is compiled and when I try to run it, i get the...
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
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
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
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.