Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-15-2009, 09:15 PM   #1
LQ Newbie
Registered: Feb 2009
Posts: 5

Rep: Reputation: 0
Trying to change my printing format

I'm doing a C Program assignment and i'm supposed to print a size 18 array... But with 3 values on 6 lines...

for (i=0; i<17; i++)
I think there's something wrong with my printf statement... When i run the program, it prints 18 lines in 1 column. How do i change it so i get it to print as 3 columns and 6 rows?
Old 03-15-2009, 10:24 PM   #2
Registered: Mar 2009
Distribution: Fedora, Slackware
Posts: 104

Rep: Reputation: 21
Your current code only prints out the loop counter, and even that in floating format. It only prints out 17 values, instead of the intended 18 values. The code prints a few tabs without values between them. Value printing happens before the value is calculated, though it isn't used anyway.

Without knowing what your code is supposed to do, I would give it a try like this:

for (i = 0; i < 18; i += 3)
printf("%10.4f\t%10.4f\t%10.4f\n",i, i+1, i+2);
I haven't compiled it (it's a quick mind hack), but it should print 3 values in a row.

And maybe replace the printf statements input with the array values, instead of the loop counter.


Linux Archive

Last edited by JaksoDebr; 04-02-2009 at 05:15 AM. Reason: additional note


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Printing man-pages in original format JZL240I-U Linux - General 3 10-26-2010 08:26 AM
Printing Legal format in OO-3 mickeyboa Fedora 1 02-17-2009 02:40 PM
change date format ust Linux - Software 4 01-15-2008 06:43 PM
samba printing format not supported spooge Linux - Networking 4 07-19-2004 10:17 PM
Possible to change the file format..? tarballed Linux - General 4 04-09-2003 02:12 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:59 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration