Thread: [Dev-C++] where is <strlib.h> ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Zachary U. <ne...@st...> - 2002-12-10 00:32:17
|
I am trying to compile programs that use <strlib.h> I checked in the
Dev-C++ \include directory and there is no such header file?
Attached is the code:
#include <ctype.h>
#include <stdio.h>
#include <strlib.h>
/* getline: get line into s, return length */
int getline(char *s, int lim)
{
char *p;
int c;
p = s;
while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
*p++ = c;
if (c == '\n')
*p++ = c;
*p = '\0';
return (int)(p - s);
}
/* atoi: convert s to an integer
*
* Here's the easy way:
* int atoi(char *s){return (int)strtoul(s, NULL, 10);}
* But I'll behave...
*/
int atoi(char *s)
{
int n, sign;
while (isspace(*s))
s++;
sign = (*s == '+' || *s == '-') ? ((*s++ == '+') ? 1 : -1) : 1;
for (n = 0; isdigit(*s); s++)
n = (n * 10) + (*s - '0'); /* note to language lawyers --
* the digits are in consecutive
* order in the character set
* C90 5.2.1
*/
return sign * n;
}
/* Shamelessly copied from my 4-12 answer
itoa() is non-standard, but defined on p.64 as having this prototype:
void itoa(int n, char s[])
Instead of this, I thought I'd use a different prototype (one I got from
the library manual of one of my compilers) since it includes all of the
above:
char *itoa(int value, char *digits, int base);
Description: The itoa() function converts an integer value into an
ASCII string of digits. The base argument specifies the number base for
the conversion. The base must be a value in the range [2..36], where 2
is binary, 8 is octal, 10 is decimal, and 16 is hexadecimal. The buffer
pointed to by digits must be large enough to hold the ASCII string of
digits plus a terminating null character. The maximum amount of buffer
space used is the precision of an int in bits + 2 (one for the sign and
one for the terminating null).
Returns: digits, or NULL if error.
*/
char *utoa(unsigned value, char *digits, int base)
{
char *s, *p;
s = "0123456789abcdefghijklmnopqrstuvwxyz"; /* don't care if s is in
* read-only memory
*/
if (base == 0)
base = 10;
if (digits == NULL || base < 2 || base > 36)
return NULL;
if (value < (unsigned) base) {
digits[0] = s[value];
digits[1] = '\0';
} else {
for (p = utoa(value / ((unsigned)base), digits, base);
*p;
p++);
utoa( value % ((unsigned)base), p, base);
}
return digits;
}
char *itoa(int value, char *digits, int base)
{
char *d;
unsigned u; /* assume unsigned is big enough to hold all the
* unsigned values -x could possibly be -- don't
* know how well this assumption holds on the
* DeathStation 9000, so beware of nasal demons
*/
d = digits;
if (base == 0)
base = 10;
if (digits == NULL || base < 2 || base > 36)
return NULL;
if (value < 0) {
*d++ = '-';
u = -value;
} else
u = value;
utoa(u, d, base);
return digits;
}
/* reverse, shamelessly copied from my 4-13 answer */
static void swap(char *a, char *b, size_t n)
{
while (n--) {
*a ^= *b;
*b ^= *a;
*a ^= *b;
a++;
b++;
}
}
void my_memrev(char *s, size_t n)
{
switch (n) {
case 0:
case 1:
break;
case 2:
case 3:
swap(s, s + n - 1, 1);
break;
default:
my_memrev(s, n / 2);
my_memrev(s + ((n + 1) / 2), n / 2);
swap(s, s + ((n + 1) / 2), n / 2);
break;
}
}
void reverse(char *s)
{
char *p;
for (p = s; *p; p++)
;
my_memrev(s, (size_t)(p - s));
}
/* strindex: return index of t in s, -1 if not found */
/* needed strchr(), so here it is: */
static char *strchr(char *s, int c)
{
char ch = c;
for ( ; *s != ch; ++s)
if (*s == '\0')
return NULL;
return *s;
}
int strindex(char *s, char *t)
{
char *u, *v, *w;
if (*t == '\0')
return 0;
for (u = s; (u = strchr(u, *t)) != NULL; ++u) {
for (v = u, w = t; ; )
if (*++w == '\0')
return (int)(u - s);
else if (*++v != *w)
break;
}
return -1;
}
/* getop */
#define NUMBER '0' /* from Chapter 4 */
int getop(char *s)
{
int c;
while ((*s = c = getch()) == ' ' || c == '\t')
;
*(s + 1) = '\0';
if (!isdigit(c) && c != '.')
return c; /* not a number */
if (isdigit(c)) /* collect integer part */
while (isdigit(*++s = c = getch()))
;
if (c == '.') /* collect fraction part */
while (isdigit(*++s = c = getch()))
;
*++s = '\0';
if (c != EOF)
ungetch(c);
return NUMBER;
}
/* Is there any more? */
Zachary Uram
John 3:16
<><
|
|
From: Per W. <pw...@ia...> - 2002-12-10 01:07:00
|
Might you possibly have thought about using the <stdlib.h> include?
/Per W
On Mon, 9 Dec 2002, Zachary Uram wrote:
> I am trying to compile programs that use <strlib.h> I checked in the
> Dev-C++ \include directory and there is no such header file?
>
> Attached is the code:
>
> #include <ctype.h>
> #include <stdio.h>
> #include <strlib.h>
>
> /* getline: get line into s, return length */
> int getline(char *s, int lim)
> {
> char *p;
> int c;
>
> p = s;
> while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
> *p++ = c;
> if (c == '\n')
> *p++ = c;
> *p = '\0';
> return (int)(p - s);
> }
>
> /* atoi: convert s to an integer
> *
> * Here's the easy way:
> * int atoi(char *s){return (int)strtoul(s, NULL, 10);}
> * But I'll behave...
> */
> int atoi(char *s)
> {
> int n, sign;
>
> while (isspace(*s))
> s++;
> sign = (*s == '+' || *s == '-') ? ((*s++ == '+') ? 1 : -1) : 1;
> for (n = 0; isdigit(*s); s++)
> n = (n * 10) + (*s - '0'); /* note to language lawyers --
> * the digits are in consecutive
> * order in the character set
> * C90 5.2.1
> */
> return sign * n;
> }
>
> /* Shamelessly copied from my 4-12 answer
>
> itoa() is non-standard, but defined on p.64 as having this prototype:
>
> void itoa(int n, char s[])
>
> Instead of this, I thought I'd use a different prototype (one I got from
> the library manual of one of my compilers) since it includes all of the
> above:
>
> char *itoa(int value, char *digits, int base);
>
> Description: The itoa() function converts an integer value into an
> ASCII string of digits. The base argument specifies the number base for
> the conversion. The base must be a value in the range [2..36], where 2
> is binary, 8 is octal, 10 is decimal, and 16 is hexadecimal. The buffer
> pointed to by digits must be large enough to hold the ASCII string of
> digits plus a terminating null character. The maximum amount of buffer
> space used is the precision of an int in bits + 2 (one for the sign and
> one for the terminating null).
>
> Returns: digits, or NULL if error.
>
> */
>
> char *utoa(unsigned value, char *digits, int base)
> {
> char *s, *p;
>
> s = "0123456789abcdefghijklmnopqrstuvwxyz"; /* don't care if s is in
> * read-only memory
> */
> if (base == 0)
> base = 10;
> if (digits == NULL || base < 2 || base > 36)
> return NULL;
> if (value < (unsigned) base) {
> digits[0] = s[value];
> digits[1] = '\0';
> } else {
> for (p = utoa(value / ((unsigned)base), digits, base);
> *p;
> p++);
> utoa( value % ((unsigned)base), p, base);
> }
> return digits;
> }
>
> char *itoa(int value, char *digits, int base)
> {
> char *d;
> unsigned u; /* assume unsigned is big enough to hold all the
> * unsigned values -x could possibly be -- don't
> * know how well this assumption holds on the
> * DeathStation 9000, so beware of nasal demons
> */
>
> d = digits;
> if (base == 0)
> base = 10;
> if (digits == NULL || base < 2 || base > 36)
> return NULL;
> if (value < 0) {
> *d++ = '-';
> u = -value;
> } else
> u = value;
> utoa(u, d, base);
> return digits;
> }
>
> /* reverse, shamelessly copied from my 4-13 answer */
>
> static void swap(char *a, char *b, size_t n)
> {
> while (n--) {
> *a ^= *b;
> *b ^= *a;
> *a ^= *b;
> a++;
> b++;
> }
> }
>
> void my_memrev(char *s, size_t n)
> {
> switch (n) {
> case 0:
> case 1:
> break;
> case 2:
> case 3:
> swap(s, s + n - 1, 1);
> break;
> default:
> my_memrev(s, n / 2);
> my_memrev(s + ((n + 1) / 2), n / 2);
> swap(s, s + ((n + 1) / 2), n / 2);
> break;
> }
> }
>
> void reverse(char *s)
> {
> char *p;
>
> for (p = s; *p; p++)
> ;
> my_memrev(s, (size_t)(p - s));
> }
>
> /* strindex: return index of t in s, -1 if not found */
>
> /* needed strchr(), so here it is: */
>
> static char *strchr(char *s, int c)
> {
> char ch = c;
>
> for ( ; *s != ch; ++s)
> if (*s == '\0')
> return NULL;
> return *s;
> }
>
> int strindex(char *s, char *t)
> {
> char *u, *v, *w;
>
> if (*t == '\0')
> return 0;
> for (u = s; (u = strchr(u, *t)) != NULL; ++u) {
> for (v = u, w = t; ; )
> if (*++w == '\0')
> return (int)(u - s);
> else if (*++v != *w)
> break;
> }
> return -1;
> }
>
> /* getop */
>
> #define NUMBER '0' /* from Chapter 4 */
>
> int getop(char *s)
> {
> int c;
>
> while ((*s = c = getch()) == ' ' || c == '\t')
> ;
> *(s + 1) = '\0';
> if (!isdigit(c) && c != '.')
> return c; /* not a number */
> if (isdigit(c)) /* collect integer part */
> while (isdigit(*++s = c = getch()))
> ;
> if (c == '.') /* collect fraction part */
> while (isdigit(*++s = c = getch()))
> ;
> *++s = '\0';
> if (c != EOF)
> ungetch(c);
> return NUMBER;
> }
>
> /* Is there any more? */
>
>
> Zachary Uram
> John 3:16
> <><
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Zachary U. <ne...@st...> - 2002-12-10 02:53:22
|
Well the code I am trying to compile uses strlib.h
If you could tell me which library calls below use strlib.h and send me
code to replace it with another library calls I would be happy to do that.
Zach
At 08:05 PM 12/9/02, you wrote:
>Might you possibly have thought about using the <stdlib.h> include?
>
>/Per W
>
>On Mon, 9 Dec 2002, Zachary Uram wrote:
>
> > I am trying to compile programs that use <strlib.h> I checked in the
> > Dev-C++ \include directory and there is no such header file?
> >
> > Attached is the code:
> >
> > #include <ctype.h>
> > #include <stdio.h>
> > #include <strlib.h>
> >
> > /* getline: get line into s, return length */
> > int getline(char *s, int lim)
> > {
> > char *p;
> > int c;
> >
> > p = s;
> > while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
> > *p++ = c;
> > if (c == '\n')
> > *p++ = c;
> > *p = '\0';
> > return (int)(p - s);
> > }
> >
> > /* atoi: convert s to an integer
> > *
> > * Here's the easy way:
> > * int atoi(char *s){return (int)strtoul(s, NULL, 10);}
> > * But I'll behave...
> > */
> > int atoi(char *s)
> > {
> > int n, sign;
> >
> > while (isspace(*s))
> > s++;
> > sign = (*s == '+' || *s == '-') ? ((*s++ == '+') ? 1 : -1) : 1;
> > for (n = 0; isdigit(*s); s++)
> > n = (n * 10) + (*s - '0'); /* note to language lawyers --
> > * the digits are in consecutive
> > * order in the character set
> > * C90 5.2.1
> > */
> > return sign * n;
> > }
> >
> > /* Shamelessly copied from my 4-12 answer
> >
> > itoa() is non-standard, but defined on p.64 as having this prototype:
> >
> > void itoa(int n, char s[])
> >
> > Instead of this, I thought I'd use a different prototype (one I got from
> > the library manual of one of my compilers) since it includes all of the
> > above:
> >
> > char *itoa(int value, char *digits, int base);
> >
> > Description: The itoa() function converts an integer value into an
> > ASCII string of digits. The base argument specifies the number base for
> > the conversion. The base must be a value in the range [2..36], where 2
> > is binary, 8 is octal, 10 is decimal, and 16 is hexadecimal. The buffer
> > pointed to by digits must be large enough to hold the ASCII string of
> > digits plus a terminating null character. The maximum amount of buffer
> > space used is the precision of an int in bits + 2 (one for the sign and
> > one for the terminating null).
> >
> > Returns: digits, or NULL if error.
> >
> > */
> >
> > char *utoa(unsigned value, char *digits, int base)
> > {
> > char *s, *p;
> >
> > s = "0123456789abcdefghijklmnopqrstuvwxyz"; /* don't care if s is in
> > * read-only memory
> > */
> > if (base == 0)
> > base = 10;
> > if (digits == NULL || base < 2 || base > 36)
> > return NULL;
> > if (value < (unsigned) base) {
> > digits[0] = s[value];
> > digits[1] = '\0';
> > } else {
> > for (p = utoa(value / ((unsigned)base), digits, base);
> > *p;
> > p++);
> > utoa( value % ((unsigned)base), p, base);
> > }
> > return digits;
> > }
> >
> > char *itoa(int value, char *digits, int base)
> > {
> > char *d;
> > unsigned u; /* assume unsigned is big enough to hold all the
> > * unsigned values -x could possibly be -- don't
> > * know how well this assumption holds on the
> > * DeathStation 9000, so beware of nasal demons
> > */
> >
> > d = digits;
> > if (base == 0)
> > base = 10;
> > if (digits == NULL || base < 2 || base > 36)
> > return NULL;
> > if (value < 0) {
> > *d++ = '-';
> > u = -value;
> > } else
> > u = value;
> > utoa(u, d, base);
> > return digits;
> > }
> >
> > /* reverse, shamelessly copied from my 4-13 answer */
> >
> > static void swap(char *a, char *b, size_t n)
> > {
> > while (n--) {
> > *a ^= *b;
> > *b ^= *a;
> > *a ^= *b;
> > a++;
> > b++;
> > }
> > }
> >
> > void my_memrev(char *s, size_t n)
> > {
> > switch (n) {
> > case 0:
> > case 1:
> > break;
> > case 2:
> > case 3:
> > swap(s, s + n - 1, 1);
> > break;
> > default:
> > my_memrev(s, n / 2);
> > my_memrev(s + ((n + 1) / 2), n / 2);
> > swap(s, s + ((n + 1) / 2), n / 2);
> > break;
> > }
> > }
> >
> > void reverse(char *s)
> > {
> > char *p;
> >
> > for (p = s; *p; p++)
> > ;
> > my_memrev(s, (size_t)(p - s));
> > }
> >
> > /* strindex: return index of t in s, -1 if not found */
> >
> > /* needed strchr(), so here it is: */
> >
> > static char *strchr(char *s, int c)
> > {
> > char ch = c;
> >
> > for ( ; *s != ch; ++s)
> > if (*s == '\0')
> > return NULL;
> > return *s;
> > }
> >
> > int strindex(char *s, char *t)
> > {
> > char *u, *v, *w;
> >
> > if (*t == '\0')
> > return 0;
> > for (u = s; (u = strchr(u, *t)) != NULL; ++u) {
> > for (v = u, w = t; ; )
> > if (*++w == '\0')
> > return (int)(u - s);
> > else if (*++v != *w)
> > break;
> > }
> > return -1;
> > }
> >
> > /* getop */
> >
> > #define NUMBER '0' /* from Chapter 4 */
> >
> > int getop(char *s)
> > {
> > int c;
> >
> > while ((*s = c = getch()) == ' ' || c == '\t')
> > ;
> > *(s + 1) = '\0';
> > if (!isdigit(c) && c != '.')
> > return c; /* not a number */
> > if (isdigit(c)) /* collect integer part */
> > while (isdigit(*++s = c = getch()))
> > ;
> > if (c == '.') /* collect fraction part */
> > while (isdigit(*++s = c = getch()))
> > ;
> > *++s = '\0';
> > if (c != EOF)
> > ungetch(c);
> > return NUMBER;
> > }
> >
> > /* Is there any more? */
> >
> >
> > Zachary Uram
> > John 3:16
> > <><
> >
> >
> >
> > -------------------------------------------------------
> > This sf.net email is sponsored by:ThinkGeek
> > Welcome to geek heaven.
> > http://thinkgeek.com/sf
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
Zachary Uram
John 3:16
<><
|
|
From: Per W. <pw...@ia...> - 2002-12-10 08:29:07
|
Yes, I can see that your code does try to use the <strlib.h> file, but
there are no such standard file. Whenever you find that Dev-C++ is missing
a standard include file, there is a very, very large proability that you
have either misspelled the include file, or that it isn't such a STANDARD
include file, but something special installed by some 3rd party tool on a
machine somewhere.
That's why I wondered if it wasn't <stdlib.h> that should be used instead.
It might also be the <string.h> file that was intended.
<stdlib.h> contains among other things atoi() implemented in your source.
<string.h> contans strchr() declaration.
/Per W
On Mon, 9 Dec 2002, Zachary Uram wrote:
> Well the code I am trying to compile uses strlib.h
> If you could tell me which library calls below use strlib.h and send me
> code to replace it with another library calls I would be happy to do that.
>
> Zach
>
> At 08:05 PM 12/9/02, you wrote:
> >Might you possibly have thought about using the <stdlib.h> include?
> >
> >/Per W
> >
> >On Mon, 9 Dec 2002, Zachary Uram wrote:
> >
> > > I am trying to compile programs that use <strlib.h> I checked in the
> > > Dev-C++ \include directory and there is no such header file?
> > >
> > > Attached is the code:
> > >
> > > #include <ctype.h>
> > > #include <stdio.h>
> > > #include <strlib.h>
> > >
> > > /* getline: get line into s, return length */
> > > int getline(char *s, int lim)
> > > {
> > > char *p;
> > > int c;
> > >
> > > p = s;
> > > while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
> > > *p++ = c;
> > > if (c == '\n')
> > > *p++ = c;
> > > *p = '\0';
> > > return (int)(p - s);
> > > }
> > >
> > > /* atoi: convert s to an integer
> > > *
> > > * Here's the easy way:
> > > * int atoi(char *s){return (int)strtoul(s, NULL, 10);}
> > > * But I'll behave...
> > > */
> > > int atoi(char *s)
> > > {
> > > int n, sign;
> > >
> > > while (isspace(*s))
> > > s++;
> > > sign = (*s == '+' || *s == '-') ? ((*s++ == '+') ? 1 : -1) : 1;
> > > for (n = 0; isdigit(*s); s++)
> > > n = (n * 10) + (*s - '0'); /* note to language lawyers --
> > > * the digits are in consecutive
> > > * order in the character set
> > > * C90 5.2.1
> > > */
> > > return sign * n;
> > > }
> > >
> > > /* Shamelessly copied from my 4-12 answer
> > >
> > > itoa() is non-standard, but defined on p.64 as having this prototype:
> > >
> > > void itoa(int n, char s[])
> > >
> > > Instead of this, I thought I'd use a different prototype (one I got from
> > > the library manual of one of my compilers) since it includes all of the
> > > above:
> > >
> > > char *itoa(int value, char *digits, int base);
> > >
> > > Description: The itoa() function converts an integer value into an
> > > ASCII string of digits. The base argument specifies the number base for
> > > the conversion. The base must be a value in the range [2..36], where 2
> > > is binary, 8 is octal, 10 is decimal, and 16 is hexadecimal. The buffer
> > > pointed to by digits must be large enough to hold the ASCII string of
> > > digits plus a terminating null character. The maximum amount of buffer
> > > space used is the precision of an int in bits + 2 (one for the sign and
> > > one for the terminating null).
> > >
> > > Returns: digits, or NULL if error.
> > >
> > > */
> > >
> > > char *utoa(unsigned value, char *digits, int base)
> > > {
> > > char *s, *p;
> > >
> > > s = "0123456789abcdefghijklmnopqrstuvwxyz"; /* don't care if s is in
> > > * read-only memory
> > > */
> > > if (base == 0)
> > > base = 10;
> > > if (digits == NULL || base < 2 || base > 36)
> > > return NULL;
> > > if (value < (unsigned) base) {
> > > digits[0] = s[value];
> > > digits[1] = '\0';
> > > } else {
> > > for (p = utoa(value / ((unsigned)base), digits, base);
> > > *p;
> > > p++);
> > > utoa( value % ((unsigned)base), p, base);
> > > }
> > > return digits;
> > > }
> > >
> > > char *itoa(int value, char *digits, int base)
> > > {
> > > char *d;
> > > unsigned u; /* assume unsigned is big enough to hold all the
> > > * unsigned values -x could possibly be -- don't
> > > * know how well this assumption holds on the
> > > * DeathStation 9000, so beware of nasal demons
> > > */
> > >
> > > d = digits;
> > > if (base == 0)
> > > base = 10;
> > > if (digits == NULL || base < 2 || base > 36)
> > > return NULL;
> > > if (value < 0) {
> > > *d++ = '-';
> > > u = -value;
> > > } else
> > > u = value;
> > > utoa(u, d, base);
> > > return digits;
> > > }
> > >
> > > /* reverse, shamelessly copied from my 4-13 answer */
> > >
> > > static void swap(char *a, char *b, size_t n)
> > > {
> > > while (n--) {
> > > *a ^= *b;
> > > *b ^= *a;
> > > *a ^= *b;
> > > a++;
> > > b++;
> > > }
> > > }
> > >
> > > void my_memrev(char *s, size_t n)
> > > {
> > > switch (n) {
> > > case 0:
> > > case 1:
> > > break;
> > > case 2:
> > > case 3:
> > > swap(s, s + n - 1, 1);
> > > break;
> > > default:
> > > my_memrev(s, n / 2);
> > > my_memrev(s + ((n + 1) / 2), n / 2);
> > > swap(s, s + ((n + 1) / 2), n / 2);
> > > break;
> > > }
> > > }
> > >
> > > void reverse(char *s)
> > > {
> > > char *p;
> > >
> > > for (p = s; *p; p++)
> > > ;
> > > my_memrev(s, (size_t)(p - s));
> > > }
> > >
> > > /* strindex: return index of t in s, -1 if not found */
> > >
> > > /* needed strchr(), so here it is: */
> > >
> > > static char *strchr(char *s, int c)
> > > {
> > > char ch = c;
> > >
> > > for ( ; *s != ch; ++s)
> > > if (*s == '\0')
> > > return NULL;
> > > return *s;
> > > }
> > >
> > > int strindex(char *s, char *t)
> > > {
> > > char *u, *v, *w;
> > >
> > > if (*t == '\0')
> > > return 0;
> > > for (u = s; (u = strchr(u, *t)) != NULL; ++u) {
> > > for (v = u, w = t; ; )
> > > if (*++w == '\0')
> > > return (int)(u - s);
> > > else if (*++v != *w)
> > > break;
> > > }
> > > return -1;
> > > }
> > >
> > > /* getop */
> > >
> > > #define NUMBER '0' /* from Chapter 4 */
> > >
> > > int getop(char *s)
> > > {
> > > int c;
> > >
> > > while ((*s = c = getch()) == ' ' || c == '\t')
> > > ;
> > > *(s + 1) = '\0';
> > > if (!isdigit(c) && c != '.')
> > > return c; /* not a number */
> > > if (isdigit(c)) /* collect integer part */
> > > while (isdigit(*++s = c = getch()))
> > > ;
> > > if (c == '.') /* collect fraction part */
> > > while (isdigit(*++s = c = getch()))
> > > ;
> > > *++s = '\0';
> > > if (c != EOF)
> > > ungetch(c);
> > > return NUMBER;
> > > }
> > >
> > > /* Is there any more? */
> > >
> > >
> > > Zachary Uram
> > > John 3:16
> > > <><
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > This sf.net email is sponsored by:ThinkGeek
> > > Welcome to geek heaven.
> > > http://thinkgeek.com/sf
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
>
> Zachary Uram
> John 3:16
> <><
>
>
|
|
From: Zachary U. <ne...@st...> - 2002-12-11 02:22:51
|
At 03:27 AM 12/10/02, Per Westermark wrote: >Yes, I can see that your code does try to use the <strlib.h> file, but >there are no such standard file. Whenever you find that Dev-C++ is missing >a standard include file, there is a very, very large proability that you >have either misspelled the include file, or that it isn't such a STANDARD >include file, but something special installed by some 3rd party tool on a >machine somewhere. > >That's why I wondered if it wasn't <stdlib.h> that should be used instead. >It might also be the <string.h> file that was intended. > ><stdlib.h> contains among other things atoi() implemented in your source. ><string.h> contans strchr() declaration. Hi Per, How can I tell the compiler to use my verson of atoi() and not the one in the stdlib.h library? I will try replacing strlib.h with string.h as well. Zach Zachary Uram John 3:16 <>< |
|
From: Sebastien M. <seb...@te...> - 2002-12-11 03:44:47
|
Hi Zach, If you use the include stdlib and want to use your own atoi definition, you have to definite it (not only the declaration) in a specific header your will include in all file where you use this function. You must be sure that your file with the definition of atoi is include AFTER stdlib.h if you use it in the same file. In all tests I made it works. Have fun in coding, Sebastien. On Tue, Dec 10, 2002 at 09:20:57PM -0500, Zachary Uram wrote: > At 03:27 AM 12/10/02, Per Westermark wrote: > >Yes, I can see that your code does try to use the <strlib.h> file, but > >there are no such standard file. Whenever you find that Dev-C++ is missing > >a standard include file, there is a very, very large proability that you > >have either misspelled the include file, or that it isn't such a STANDARD > >include file, but something special installed by some 3rd party tool on a > >machine somewhere. > > > >That's why I wondered if it wasn't <stdlib.h> that should be used instead. > >It might also be the <string.h> file that was intended. > > > ><stdlib.h> contains among other things atoi() implemented in your source. > ><string.h> contans strchr() declaration. > > > Hi Per, > > How can I tell the compiler to use my verson of atoi() and not the one in > the stdlib.h library? > I will try replacing strlib.h with string.h as well. > > Zach > > Zachary Uram > John 3:16 > <>< > > > > ------------------------------------------------------- > This sf.net email is sponsored by: > With Great Power, Comes Great Responsibility > Learn to use your power at OSDN's High Performance Computing Channel > http://hpc.devchannel.org/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > -- Time remaining: 28 weeks 6 days 3 hours 6 minutes |
|
From: Zachary U. <ne...@st...> - 2002-12-11 04:14:01
|
Hi Sebastien, Ah is this what an "inline function declaration" is? How can I do this in the header file? Zach At 11:04 PM 12/10/02, Sebastien Morand wrote: >Hi Zach, >If you use the include stdlib and want to use your own atoi >definition, you have to definite it (not only the declaration) in a >specific header your will include in all file where you use this function. >You must be sure that your file with the definition of atoi is include >AFTER stdlib.h if you use it in the same file. In all tests I made it >works. > >Have fun in coding, >Sebastien. Zachary Uram John 3:16 <>< |
|
From: Sebastien M. <seb...@te...> - 2002-12-11 06:55:12
|
Hi Zach,
Not at all, you can try to put the word inline in this case. If your
function isn't too big, and isn't recursive (and have not weird
properties, like calling a funtion calling itself) this function will
be certainly inline everywhere you will use it so it will be faster
since the code of the function will be direclty put instead of the
call of the function. It it can't inline it and you put even so the
word inline, the worst you can get is a warning. Note that if you
compile with -O3 (gcc option) every function will be try to put as an
inline function.
The way I suggest was just to have the declaration in the same time
than the definition to be sure that the compiler use your function. If
you put your function in another module and link the module together,
the compiler will use the stdlib function :(
For instance:
/************
* test1.cpp *
*************/
#include <stdlib.h> /* This header has to be set BEFORE teset.h,
* otherwise you get a conflict in the definition,
* the compiler will say that the atoi function is
* already defined. */
#include "test.h"
int main()
{
atoi();
return 0;
}
/*********
* test.h *
**********/
int atoi(const char *)
{
printf("It's my atoi :)\n");
return 0;
}
if you compile gcc test1.cpp and run the a.out you get:
It's my atoi :)
as output.
But if you name the test.h in test2.cpp, remove the #include "test.h"
line of the test1.cpp file and compile gcc test1.cpp test2.cpp and run
the a.out, you get no output because the atoi function used is not
yours!
Now if you change
int atoi(const char *)
by
inline int atoi(const char *)
you function will run faster, but the behaviour will be the same,
anyway, it's always a good thing to make the inline word. By the way,
don't forget to put -O1, -O2 or -O3, because by default no function
will be inlined, even if you use the inline word.
I hope it's more clear, maybe you knew most of things I said :)
Sebastien.
On Tue, Dec 10, 2002 at 11:12:03PM -0500, Zachary Uram wrote:
> Hi Sebastien,
>
> Ah is this what an "inline function declaration" is? How can I do this in
> the header file?
>
> Zach
>
> At 11:04 PM 12/10/02, Sebastien Morand wrote:
> >Hi Zach,
> >If you use the include stdlib and want to use your own atoi
> >definition, you have to definite it (not only the declaration) in a
> >specific header your will include in all file where you use this function.
> >You must be sure that your file with the definition of atoi is include
> >AFTER stdlib.h if you use it in the same file. In all tests I made it
> >works.
> >
> >Have fun in coding,
> >Sebastien.
>
> Zachary Uram
> John 3:16
> <><
>
--
Time remaining: 28 weeks 6 days 0 hours 0 minutes
|
|
From: Zachary U. <ne...@st...> - 2002-12-11 08:07:57
|
At 02:15 AM 12/11/02, Sebastien Morand wrote: >Hi Zach, > >Not at all, you can try to put the word inline in this case. If your >function isn't too big, and isn't recursive (and have not weird >properties, like calling a funtion calling itself) this function will >be certainly inline everywhere you will use it so it will be faster >since the code of the function will be direclty put instead of the >call of the function. It it can't inline it and you put even so the >word inline, the worst you can get is a warning. Note that if you >compile with -O3 (gcc option) every function will be try to put as an >inline function. > >The way I suggest was just to have the declaration in the same time >than the definition to be sure that the compiler use your function. If >you put your function in another module and link the module together, >the compiler will use the stdlib function :( [snip] Merci beaucoup Sebastien. Je vois :) C'est bon~ Zach Zachary Uram John 3:16 <>< |
|
From: Per W. <pw...@ia...> - 2002-12-11 09:21:35
|
You may continue to include stdlib.h as normal. Put your atoi() in either your main program, or in a separate source file. Dev-C++ will make sure that the object file containing your atoi will be linked before the standard libraries, i.e. that your version of atoi will be used instead of the implementation in the standard libraries. The reason you want stdlib.h both when implementing and when using your atoi is that it must have exactly the same format as the original implementation, or any calls from within the standard libraries will fail. One other thing - if the original implementation of atoi in the standard libraries was placed in a source file together with a number of other standard functions, you might have to replace these functions too. A library is just a collection of individual object files, and the linker may never perform linking on individual functions or variables. All linking is performed on complete object files. I saw some references in a couple of other mails about using inline or placing the atoi declaration in a different include file etc. No, you don't need to do these steps. The linker thinks it's ok to have the same symbol defined in your object files and in the libraries. It will just pick the object file instead of extracting an implementation from the library file. The only reason for taking extra steps is if you want to be able to call both a new and an old implementation in the same program. In that case you have to do something like: #define atoi my_atoi in an include file, to map all calls to your new atoi. Then in the part of the program where you want to access the original atoi, you have to do: #undef atoi return atoi(x) Note that this concept doesn't work if atoi would already from the beginning be a #define'd symbol. The concept of fooling around with #define is for example used in a number of environments, to replace the memory allocation functions with debug versions that checks heap validity and that you remember to release all memory on program end. /Per W On Tue, 10 Dec 2002, Zachary Uram wrote: > At 03:27 AM 12/10/02, Per Westermark wrote: > >Yes, I can see that your code does try to use the <strlib.h> file, but > >there are no such standard file. Whenever you find that Dev-C++ is missing > >a standard include file, there is a very, very large proability that you > >have either misspelled the include file, or that it isn't such a STANDARD > >include file, but something special installed by some 3rd party tool on a > >machine somewhere. > > > >That's why I wondered if it wasn't <stdlib.h> that should be used instead. > >It might also be the <string.h> file that was intended. > > > ><stdlib.h> contains among other things atoi() implemented in your source. > ><string.h> contans strchr() declaration. > > > Hi Per, > > How can I tell the compiler to use my verson of atoi() and not the one in > the stdlib.h library? > I will try replacing strlib.h with string.h as well. > > Zach > > Zachary Uram > John 3:16 > <>< > > |