Discussion:
OT: cpp programing question
(too old to reply)
Jeff
2002-04-03 22:03:01 UTC
Permalink
Hi programming gurus!

I have this psuedo project at work. I have some code a guy wrote in M$
CPP. There are some function call in it that I don't know how to port.
Can anybody help me? Here they are:

error log:
killer.cpp:249: `itoa' undeclared (first use this function)

source:
itoa(count[j],output,10);

error log:
killer.cpp:271: `_findfirst' undeclared (first use this function)

source:
if( (hFile = _findfirst( "*.APX1", &c_file )) == -1L )


There are several find??? functions in this code. Findfirst, findnext
and
finddata & findclose. Does anybody know if these function calls are
portable and what would be the equivalent function call? Thanks in
advance for your help.

Jeff
----
That dog sucks! He keeps chewing on my head!
Mike regarding Goose
Dave Kjar
2002-04-03 23:13:01 UTC
Permalink
Post by Jeff
killer.cpp:249: `itoa' undeclared (first use this function)
itoa(count[j],output,10);
most posix proggies would use
sprintf(output,"%10d",count[j]);
Post by Jeff
killer.cpp:271: `_findfirst' undeclared (first use this function)
if( (hFile = _findfirst( "*.APX1", &c_file )) == -1L )
most posix proggies would either use glob() or readdir() and
getdents() -- see the man pages
Post by Jeff
finddata & findclose. Does anybody know if these function calls are
portable and what would be the equivalent function call? Thanks in
There are some porting libes out there, but the posix libs
are more standard, and port the other direction well.
--
+-----------------------+-------------------------+
| Dave Kjar | <***@kjar.org> |
| Satlug Administrator | <***@satlug.org> |
| Linux advocate | <***@satlug.org> |
| MICROSOFT : ETHICS :: osama : religion |
+-----------------------+-------------------------+
Dave Kjar
2002-04-03 23:16:01 UTC
Permalink
Post by Dave Kjar
sprintf(output,"%10d",count[j]);
Also, meant to remind you that snprintf() is better :)
--
+-----------------------+-------------------------+
| Dave Kjar | <***@kjar.org> |
| Satlug Administrator | <***@satlug.org> |
| Linux advocate | <***@satlug.org> |
| MICROSOFT : ETHICS :: osama : religion |
+-----------------------+-------------------------+
Borries Demeler
2002-04-04 06:51:01 UTC
Permalink
Post by Jeff
Hi programming gurus!
I have this psuedo project at work. I have some code a guy wrote in M$
CPP. There are some function call in it that I don't know how to port.
killer.cpp:249: `itoa' undeclared (first use this function)
If I recall correctly from my first programming attempts under DOS,
this function converts an integer to a string.
The best way to accomplish something like this is to use sprintf().

THe other functions I have never seen before. I don't think they are
part of standard cpp. You need to find out what they do and recode them,
I'm afraid. I may be wrong about that, better get some other opinions on that.

-Borries
Post by Jeff
killer.cpp:271: `_findfirst' undeclared (first use this function)
if( (hFile = _findfirst( "*.APX1", &c_file )) == -1L )
There are several find??? functions in this code. Findfirst, findnext
and
finddata & findclose. Does anybody know if these function calls are
portable and what would be the equivalent function call? Thanks in
advance for your help.
Jeff
----
That dog sucks! He keeps chewing on my head!
Mike regarding Goose
_______________________________________________
Satlug mailing list
http://alamo.satlug.org/mailman/listinfo/satlug
Clayton Pigwillow
2002-04-04 21:16:01 UTC
Permalink
Post by Borries Demeler
Post by Jeff
Hi programming gurus!
I have this psuedo project at work. I have some code a guy wrote in M$
CPP. There are some function call in it that I don't know how to port.
killer.cpp:249: `itoa' undeclared (first use this function)
If I recall correctly from my first programming attempts under DOS,
this function converts an integer to a string.
The best way to accomplish something like this is to use sprintf().
THe other functions I have never seen before. I don't think they are
part of standard cpp. You need to find out what they do and recode them,
I'm afraid. I may be wrong about that, better get some other opinions on that.
-Borries
I seem to recall itoa being used back when I was writing K&R C with a Borland
implementation (could have been m$, time really zooms by). I can't find it
in Plauger's book, but that could be caused by the potato juice.

If it's in loads of places, an alternative to using sprintf is writing your
own itoa (using sprintf). I assume speed isn't too important here.
--
-----Screamin' Clay Pig------------
Bruce Dubbs
2002-04-04 21:58:01 UTC
Permalink
Post by Clayton Pigwillow
Post by Borries Demeler
Post by Jeff
Hi programming gurus!
I have this psuedo project at work. I have some code a guy wrote in M$
CPP. There are some function call in it that I don't know how to port.
killer.cpp:249: `itoa' undeclared (first use this function)
If I recall correctly from my first programming attempts under DOS,
this function converts an integer to a string.
The best way to accomplish something like this is to use sprintf().
THe other functions I have never seen before. I don't think they are
part of standard cpp. You need to find out what they do and recode them,
I'm afraid. I may be wrong about that, better get some other opinions on that.
-Borries
I seem to recall itoa being used back when I was writing K&R C with a Borland
implementation (could have been m$, time really zooms by). I can't find it
in Plauger's book, but that could be caused by the potato juice.
If it's in loads of places, an alternative to using sprintf is writing your
own itoa (using sprintf). I assume speed isn't too important here.
You can write itoa with a lot less overhead than sprintf:

char* p = &buffer[0];

if (num < 0) {*p++ = '-'; num = -num;}
if (num==0) { *p = '0'; return;}
while (num > 0) {*p++ = (num % 10) | '0'; num /=10;}
return;

-- Bruce

Kase Saylor
2002-04-04 08:59:00 UTC
Permalink
For all of string needs, I suggest that you use the available string class.
Include string.h. It has some great functionality like: find_first_of,
find_first_not_of, find, etc.

The iota function does the following (from internet
http://gcc.gnu.org/onlinedocs/libstdc++/ext/sgiexts.html):

The iota function wins the award for Extension With the Coolest Name. It
"assigns sequentially increasing values to a range. That is, it assigns
value to *first, value + 1 to *(first + 1) and so on." Quoted from SGI
documentation.

void iota(_ForwardIter first, _ForwardIter last, _Tp value);
Post by Jeff
Hi programming gurus!
I have this psuedo project at work. I have some code a guy wrote in M$
CPP. There are some function call in it that I don't know how to port.
killer.cpp:249: `itoa' undeclared (first use this function)
itoa(count[j],output,10);
killer.cpp:271: `_findfirst' undeclared (first use this function)
if( (hFile = _findfirst( "*.APX1", &c_file )) == -1L )
There are several find??? functions in this code. Findfirst, findnext
and
finddata & findclose. Does anybody know if these function calls are
portable and what would be the equivalent function call? Thanks in
advance for your help.
Jeff
----
That dog sucks! He keeps chewing on my head!
Mike regarding Goose
_______________________________________________
Satlug mailing list
http://alamo.satlug.org/mailman/listinfo/satlug
KASE J. SAYLOR
Southwest Research Insitute
Electrical Engineer Intern
210-522-3703
***@SwRI.edu


_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
Borries Demeler
2002-04-04 09:12:01 UTC
Permalink
Post by Kase Saylor
For all of string needs, I suggest that you use the available string class.
Include string.h. It has some great functionality like: find_first_of,
find_first_not_of, find, etc.
The iota function does the following (from internet
The iota function wins the award for Extension With the Coolest Name. It
"assigns sequentially increasing values to a range. That is, it assigns
value to *first, value + 1 to *(first + 1) and so on." Quoted from SGI
documentation.
void iota(_ForwardIter first, _ForwardIter last, _Tp value);
Here is another way to convert an integer to a character, but I am
sure that's not what you were after:

#include <iostream.h>

int main()
{
int i;
char c;
for (i=0; i<255; i++)
{
c = (char) i;
cout << "char[" << i << "]: " << c << endl;
}
return(0);
}

(save to itoa.cpp and compile with g++ itoa.cpp -o itoa)

-Borries
Loading...