Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Force printf format?

Reply
Thread Tools

Force printf format?

 
 
hamsya@yahoo.fr
Guest
Posts: n/a
 
      10-22-2007
Hello world

I have some ASCII files with a number of float values inside. These
files are created by a Fortran code which I can not modify.

On the other hand, I am working on a C application which is supposed
to output the same data.

My dream is to run any diff program on these files to validate my C
application against the Fortran one, but for now it seems impossible.

Values issued from Fortran are stored as "0.1000000E+01".
The C printf("%14.7E", value) gives "1.0000000E+00".

Is there a way to control printf in order to have the same
representation in both cases?

Crea.

 
Reply With Quote
 
 
 
 
Charlie Gordon
Guest
Posts: n/a
 
      10-22-2007
<(E-Mail Removed)> a ecrit dans le message de news:
(E-Mail Removed) om...
> Hello world
>
> I have some ASCII files with a number of float values inside. These
> files are created by a Fortran code which I can not modify.
>
> On the other hand, I am working on a C application which is supposed
> to output the same data.
>
> My dream is to run any diff program on these files to validate my C
> application against the Fortran one, but for now it seems impossible.
>
> Values issued from Fortran are stored as "0.1000000E+01".
> The C printf("%14.7E", value) gives "1.0000000E+00".
>
> Is there a way to control printf in order to have the same
> representation in both cases?


Not that I know, but you could write a utility to compare the files by
parsing both with fscanf and comparing the numbers. If you are lucky, the
difference you mention should not show in the resulting numbers.

--
Chqrlie.


 
Reply With Quote
 
 
 
 
hamsya@yahoo.fr
Guest
Posts: n/a
 
      10-23-2007
> Not that I know, but you could write a utility to compare the files by
> parsing both with fscanf and comparing the numbers.


Yes I could but I really don't want to do this There are several
types of data files to compare, and I'll have to write a separate
parser for each file format.

Anyway thanks for your answer, Charlie

 
Reply With Quote
 
Charlie Gordon
Guest
Posts: n/a
 
      10-23-2007
<(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed). com...
>> Not that I know, but you could write a utility to compare the files by
>> parsing both with fscanf and comparing the numbers.

>
> Yes I could but I really don't want to do this There are several
> types of data files to compare, and I'll have to write a separate
> parser for each file format.
>
> Anyway thanks for your answer, Charlie


In this case, you might want to write a utility function to format your
numbers appropriately by post processing the output of snprintf:

void post_process(char *p) {
/* p points to a buffer holding the converted value as produced by
sprintf */
/* this buffer is assumed to be large enough for one extra digit */
int exp;
if (*p == '+' || *p == ' ' || *p == '-')
number++;
if (isdigit((unsigned char)*p) && p[1] == '.' && strchr(p, 'E')) {
p[1] = *p;
*p = '.';
p = strchr(p, 'E') + 1;
if (*p == '+') {
p += 1;
sprintf(p, "%d", atoi(p) + 1);
}
}

This is a general idea, you may have to customize this function to produce
the desired format for specific values of the exponent.

--
Chqrlie.


 
Reply With Quote
 
hamsya@yahoo.fr
Guest
Posts: n/a
 
      10-24-2007
Great! I'll implement something like this, thank you for the idea

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nike air force one, air force 1, air force one low cut, air force one abdul_razak@indiatimes.com Digital Photography 2 12-31-2008 04:29 PM
Nike Air Force Ones,Air Force One Air Force One-1 lky52193@gmail.com Computer Support 0 01-17-2008 04:40 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:46 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:34 PM
bus error with printf line included, error without printf line? ben C Programming 4 06-26-2004 04:42 PM



Advertisments