C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 19th, 2004, 06:25 AM
kepler kepler is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 289 kepler User rank is Sergeant (500 - 2000 Reputation Level)kepler User rank is Sergeant (500 - 2000 Reputation Level)kepler User rank is Sergeant (500 - 2000 Reputation Level)kepler User rank is Sergeant (500 - 2000 Reputation Level)kepler User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 5 h 38 m 43 sec
Reputation Power: 14
C++ to C translation

Hi,

I've got a C++ file with a function I want to use - whatconstel (pp, epoch).

I've tryied to call it from my main program and compile - but it gives «hundreds of errors». First, I don't know how to declare it; secondo how to call it; third, how to translate it.
The code is this:

#include "precess.c";
/*precess - this routine is already made and functioning*/
#include <stdio.h>
#if __STDC__
static int islow (char *);
static int isup (char *);
static int isnumber (char *);
static int skipwh(char *);
double sqrt (double);
double sin (double);
double cos (double);
double atan2 (double, double);
double asin (double);
int precess (double *, double, int);
#else
static int islow(), isup(), isnumber(), skipwh();
double sqrt(), sin(), cos(), atan2(), asin();
int precess();
#endif

#define RTD 57.295779513082320877

#define NCON 89
char *constel[NCON] = {
"And Andromedae",
(etc...)
"Vul Vulpeculae",
};



/* Greek letters
*/

#define NGREEK 24
char *greek[NGREEK] = {
"alpha",
(etc...)
"omega",
};

int showcname( in )
char *in;
{
char *g, *p, *q;
char ans[80];
int i;


p = in;
q = ans;


skipwh(p);
if( isnumber(p) )
{
while( isnumber(p) )
*q++ = *p++;
}
skipwh(p);
*q++ = ' ';

if( islow(p) )
{
for( i=0; i<NGREEK; i++ )
{
g = greek[i];
if( (*p == *g) && (*(p+1) == *(g+1)) )
break;
}
if( i < NGREEK )
{
while( *g != '\0' )
*q++ = *g++;
}
while( islow(p) )
++p;
}
skipwh(p);
/* copy things like "-a" until uppercase letter found */
while( (*p != '\0') && !isup(p) )
*q++ = *p++;

*q++ = ' ';

if( isup(p) )
{
/* Check the list of constellation names */
for( i=0; i<NCON; i++ )
{
g = constel[i];
if( (*p == *g) && ( *(p+1) == *(g+1) )
&& ( *(p+2) == *(g+2) ) )
break;
}
/* Get the name found */
if( i < NCON )
{
g += 4;
while( *g != '\0' )
*q++ = *g++;
p += 3;
}
}
skipwh(p);
*q++ = ' ';
while( *p )
*q++ = *p++;
*q++ = '\0';
/* convert all '_' characters to spaces */
q = ans;
while( *q != '\0' )
{
if( *q == '_' )
*q = ' ';
++q;
}
printf( "\n %s\n", ans );
return(0);
}




static int islow(p)
char *p;
{
if( (*p >= 'a') && (*p <= 'z') )
return(1);
else
return(0);
}



static int isup(p)
char *p;
{
if( (*p >= 'A') && (*p <= 'Z') )
return(1);
else
return(0);
}




static int isnumber(p)
char *p;
{
if( (*p >= '0') && (*p <= '9') )
return(1);
else
return(0);
}



static int skipwh(p)
char *p;
{
while( ((*p == ' ') || (*p == '\t') || (*p == '_'))
&& (*p != '\0') && (*p != '\n') && (*p != '\r') )
++p;
return(0);
}



#define NBNDRIES 357
long bndries[4*NBNDRIES] = {
0L, 86400L, 316800L, 84L,
(etc...)
0L, 86400L, -324000L, 58L,
};


char *
whatconstel (pp, epoch)
double pp[];
double epoch;
{
int i, k;
double ra, dec, d;
double p[3];

for (i = 0; i < 3; i++)
p[i] = pp[i];

precess (p, epoch, 1);
precess (p, 2405889.25855, -1);
d = p[0] * p[0] + p[1] * p[1] + p[2] * p[2];
d = sqrt (d);
ra = atan2 (p[1], p[0]) * (RTD * 3600. / 15.);
if (ra < 0.0)
ra += 86400.0;
dec = asin (p[2] / d) * (RTD * 3600.);

for (i = 0; i < NBNDRIES; i++)
{
k = i << 2;
if (ra >= bndries[k] && ra < bndries[k+1] && dec > bndries[k+2])
{
k = (int) bndries[k+3];
return (constel[k]);
}
}
return ("?? constellation not found");
}

#if 0
/* Test program */
double J2000 = 2451545.0;
double STR = 4.8481368110953599359e-6;

test (r,d)
double r, d;
{
double c, p[3], jd;

d /= RTD;
r *= 15.0/RTD;
c = cos(d);
p[2] = sin(d);
p[0] = c * cos(r);
p[1] = c * sin(r);
jd = 2433282.423; /* 1950.0 Besselian epoch */
printf ("%8.4f %9.4f %s\n", r, d, whatconstel (p, jd));
}


int
main()
{
/* The following is an example of the output of the program:
RA = 9.0000 DEC = 65.0000 IS IN CONSTELLATION UMa
RA = 23.5000 DEC = -20.0000 IS IN CONSTELLATION Aqr
RA = 5.1200 DEC = 9.1200 IS IN CONSTELLATION Ori
RA = 9.4555 DEC = -19.9000 IS IN CONSTELLATION Hya
RA = 12.8888 DEC = 22.0000 IS IN CONSTELLATION Com
RA = 15.6687 DEC = -12.1234 IS IN CONSTELLATION Lib
RA = 19.0000 DEC = -40.0000 IS IN CONSTELLATION CrA
RA = 6.2222 DEC = -81.1234 IS IN CONSTELLATION Men */
test (9.0, 65.0);
test (23.5, -20.0);
test (5.12, 9.12);
test (9.4555, -19.9);
test (12.8888, 22.0);
test (15.6687, -12.1234);
test (19.0, -40.0);
test (6.2222, -81.1234);
exit(0);
}
#endif


Can someone help me translate the little differences that might exist, and tell me how to use this file in my main program?

Thanks in advance.

Regards,

Kepler

Reply With Quote
  #2  
Old October 19th, 2004, 06:29 AM
DaWei_M's Avatar
DaWei_M DaWei_M is offline
Renaissance Redneck
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
Posts: 8,473 DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Weeks 6 h 48 m 41 sec
Warnings Level: 20
Number of bans: 3
Reputation Power: 3242
Please read the post for new users and put code tags around your code to preserve the indentation. It's right at the top of the forum, says READ THIS FIRST.
__________________
Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
DaWei on Pointers Politically Incorrect.

Reply With Quote
  #3  
Old October 19th, 2004, 06:56 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,200 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Week 1 Day 11 h 47 m 52 sec
Reputation Power: 11
what let you believe it's a c++ progr ?
i find, it's a very worst writted (K&R style, NOT ansi)
essay for a 'c' code.
i did not study it, scanning it i saw errors, globals ...
sure it does not run.
i will&&can not believe, about 40 years after K&R,
that's the level of modern 'c' (+= other) programmers.

Reply With Quote
  #4  
Old October 19th, 2004, 07:03 AM
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jan 2004
Location: near St. Louis Illinois
Posts: 3,288 Ancient Dragon User rank is Sergeant (500 - 2000 Reputation Level)Ancient Dragon User rank is Sergeant (500 - 2000 Reputation Level)Ancient Dragon User rank is Sergeant (500 - 2000 Reputation Level)Ancient Dragon User rank is Sergeant (500 - 2000 Reputation Level)Ancient Dragon User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 20 h 37 m 22 sec
Reputation Power: 22
Quote:
Originally Posted by guggach
i will&&can not believe, about 40 years after K&R,
that's the level of modern 'c' (+= other) programmers.


probably some very very old code he dug out of a book or online. I hope schools don't teach that style any more

Reply With Quote
  #5  
Old October 19th, 2004, 07:27 AM
DaWei_M's Avatar
DaWei_M DaWei_M is offline
Renaissance Redneck
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
Posts: 8,473 DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level)DaWei_M User rank is General 34th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Weeks 6 h 48 m 41 sec
Warnings Level: 20
Number of bans: 3
Reputation Power: 3242
Global declarations are perhaps infelicitous, but there's a qualitative distinction between error and poor judgement.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > C++ to C translation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap