[Kstars-devel] stupd C++ question
Mark Hollomon
markhollomon at comcast.net
Mon Sep 1 16:26:48 CEST 2003
my sscanf is a little rusty, but this would seem to be a job better left to
perl or python or something.
#!/usr/bin/perl -w
use strict;
my $line = "064509.25";
my ($rah, $ram, $ras) = unpack("a2a2a5", $line);
#
# force to numbers, not really necessary. but the output will look more
# as expected.
#
($rah, $ram, $ras) = map { $_+0 } ($rah, $ram, $ras);
print join(":", $rah, $ram, $ras), "\n";
#
# or as a one liner....
#
# print join(":", map{ $_+0} unpack("a2a2a5", $line)), "\n";
On Monday 01 September 2003 15:03, Jason Harris wrote:
> Hello,
>
> I am trying to write a straight C++ program to parse the star catalog,
> so I can add some additional genitive names I found. I usually use
> fortran for these little 20-line programs, but it isn't flexible enough
> for this purpose. I'm afraid I am a bit lost without my Qt/KDE
> crutches! :)
>
> Why doesn't this simple program work?
>
> -----------------------------
> #include <iostream>
> #include <cstring>
> using namespace std;
>
> int main() {
> int rah, ram;
> float ras;
> char *line = "064509.25";
>
> sscanf( line, "%2d%2d%5.2f", &rah, &ram, &ras );
>
> cout << rah << ":" << ram << ":" << ras << endl;
> }
> -----------------------------
> When I run it, I get:
> 6:45:3.98821e-34
>
> Why isn't the third field getting set to "9.25"?
>
> thanks for any ideas,
> Jason
--
Mark Hollomon
More information about the Kstars-devel
mailing list