LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-03-2012, 12:38 AM   #1
casualzone
Member
 
Registered: Jan 2010
Posts: 189

Rep: Reputation: 15
printf format does not work !


I try to print out the a input text file to a proper format so that it is more readable (by column).

BUT the printf %-30s does not work!!
the columns are not aligned!!
could somoeone help me?

Code:
while( $line < $file_line )
{
        $temp = @file[$line] ;
        chomp( $temp );
        @split = split( $delimiter, $temp);
        for($i=0; $i<=$#split; $i++)
        {
                if( @split[$i] =~ m/[0-9,a-z,A-Z]/ ) #eliminate embedded code
                {
                printf("%-30s", @split[$i]);  #display in xterm
                printf( NEWFILE "%-30s", @split[$i]);
                }
        }
        printf( "\n");
        printf( NEWFILE "\n");
        $line++;
}
 
Old 01-03-2012, 01:24 AM   #2
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,420

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
I think the problem is with the '-' you are using between % and 30. Try removing '-' and use it as '%30s'
 
Old 01-03-2012, 09:46 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 01-04-2012, 02:31 AM   #4
casualzone
Member
 
Registered: Jan 2010
Posts: 189

Original Poster
Rep: Reputation: 15
i thought it is the correct format "%-30s"
 
  


Reply



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
Can't inject x00 value with bash-printf using string format vulnerability in x64 kaos_npc Programming 5 05-27-2014 02:14 PM
What is type size_t's format in printf? duyuyang Linux - Newbie 7 07-20-2011 01:04 AM
'C' error in printf warning: format ‘%lf’ expects type ‘double’ ... SuperNomad Programming 4 11-17-2009 09:07 AM
Minus sign in printf format string doesn't work. zebela Linux - Newbie 4 06-13-2008 01:32 AM
Is there a currency format with printf() ? LUB997 Programming 1 01-03-2005 08:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:26 PM.

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