Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 20-11-2007, 06:02 AM   #1 (permalink)
Think Well Before You Do
 
thinker's Avatar
 
Join Date: Oct 2007
Location: bangalore
Posts: 13
Unhappy please help me out with this problem????


I think it's fairly simple, but for some reason I can't find the answer.
I want to write to a file, in a certain format; however, it doesn't write it exactly as I want:

C Syntax (Toggle Plain Text)
1. fprintf(fpout, "ATOM %2d %c %c %d %02.3f %02.3f %02.3f\n", i, 'C', 'C', 1, *(x+i), *(y+i), *(z+i));
2.


This produces something like this:
ATOM 6 C C 1 5.047 5.964 17.520
ATOM 7 C C 1 10.631 18.405 10.309
ATOM 8 C C 1 16.209 3.768 17.726
ATOM 9 C C 1 11.412 1.535 16.305
ATOM 10 C C 1 19.698 2.367 17.878
ATOM 11 C C 1 15.690 2.018 5.066

(in the text file everything is in OK up to the 1).
However, as you can see, the coordinates (the last 3 floats).

because some numbers are in 2.3f format, and others in 1.3f format, they don't line up as i want. I tried using "%02.3f" so that it embeds a 0 in front of the coordinate IF the coordinate is in 1.3f format. (Still with me? ). But that doesn't work; the 0 isn't put in the file.
For some reason it does work with the %2d in the 2nd column.

Any ideas?
thinker is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 20-11-2007, 05:29 PM   #2 (permalink)
In The Zone
 
hansraj's Avatar
 
Join Date: Sep 2004
Location: Pune
Posts: 436
Default Re: please help me out with this problem????

man u r probably dealing with something too fundoo..... i cant make out a single line of u r post except the last one. hope u find some good geek around
__________________
"An eye for an eye leaves the world blind." - Gandhi

Athlon II X 4 620 Quad Core, Gigabyte GA-MA 785 GPMT, G-Skill DDR3 1333 Mhz 2GB X 2, Seagate 1 TB + Seagate 80 GB, Win 7 Ultimate 64 Bit
hansraj is offline  
Old 20-11-2007, 10:10 PM   #3 (permalink)
Pawned!... Beyond GODLIKE
 
fun2sh's Avatar
 
Join Date: May 2006
Location: World Of Warcraft -DOTA
Posts: 1,051
Default Re: please help me out with this problem????

wil u put ur complete program here???
n there is a seperate programin section for all these
__________________
If God has indeed created Himself in His own image, then I submit to you that God is a cockroach :mrgreen:!!!!!!!!
fun2sh is offline  
Old 20-11-2007, 10:48 PM   #4 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: please help me out with this problem????

Try this example. I had to remove the pre-decimal specifier, so that the printf obeys the width set, dunno why it didn't though, when coupled with that specifier.

Code:
#include<stdio.h>

int main()
{
    int i;
    float a[4]={5.123,10.444,16.555,11.777},b[4]={6.321,7.432,8.654,18.987},c[4]={13.124,7.442,19.201,4.666};
    for(i=0;i<4;i++)
    printf("ATOM %02d %c %c %d %06.3f %06.3f %06.3f\n", i, 'C', 'C', 1, a[i], b[i], c[i]);
}
Outputs as:
Code:
ATOM 00 C C 1 05.123 06.321 13.124
ATOM 01 C C 1 10.444 07.432 07.442
ATOM 02 C C 1 16.555 08.654 19.201
ATOM 03 C C 1 11.777 18.987 04.666
There you go, all are lined up evenly.

I think using C++ would be better for formatting your outputs the easy way. Why choose C?
__________________
Harsh J
www.harshj.com

Last edited by QwertyManiac; 20-11-2007 at 10:56 PM.
QwertyManiac is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem With Data Recovary Software Problem Stellar Phoenix njm Software Q&A 1 08-05-2007 12:31 PM
Problem Related To Dvd and Iso Buring , any genius here who can resolve this problem vijayendra QnA (read only) 2 14-01-2007 09:38 AM
Problem!Problem!Problem Help Me November Cd And December dvd Doesnt Work yyy??? sourav_digit QnA (read only) 3 27-12-2006 02:33 PM
Serius problem with my screen. Can u tell it s/w or hard ware problem . tusarks Hardware Q&A 7 12-06-2006 01:58 PM
fedora cd iso problem(installation from hard drive problem) harmax Open Source 3 01-07-2005 11:34 AM

 
Latest Threads
- by topgear
- by abhidev
- by clmlbx
- by Sarath

Advertisement




All times are GMT +5.5. The time now is 05:38 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2