开发者

What functions in the GNU C runtime library are in the standard library?

How do I find out what CRT functions supporte开发者_如何学运维d by GNU C are part of the standard library? As an example: atoi() and itoa().


atoi() is part of the standard library.
itoa() is not part of the standard library.


You can implement it this way to use it:

 #include <string.h>

 void itoa(int input, void (*subr)(char));

 void itoa(int n, char s[]) {
     int i, sign;

     if ((sign = n) < 0)  /* record sign */
         n = -n;          /* make n positive */
     i = 0;
     do {       /* generate digits in reverse order */
         s[i++] = n % 10 + '0';   /* get next digit */
     } while ((n /= 10) > 0);     /* delete it */
     if (sign < 0)
         s[i++] = '-';
     s[i] = '\0';
     reverse(s);
 }


 /* reverse:  reverse string s in place */
 void reverse(char s[]) {
     int i, j;
     char c;

     for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
         c = s[i];
         s[i] = s[j];
         s[j] = c;
     }
 }

See comments to see why this is striked through, although it works fine for other values.


Quoting part of Wikipedia's first paragraphs for each of atoi and itoa:

atoi

atoi is a function in the C programming language that converts a string into an integer numerical representation. atoi stands for ASCII to integer. It is included in the C standard library header file stdlib.h.

itoa

The itoa (integer to ASCII) function is a widespread non-standard extension to the standard C programming language. It cannot be portably used, as it is not defined in any of the C language standards; however, compilers often provide it through the header while in non-conforming mode, because it is a logical counterpart to the standard library function atoi.


The answer to your question is rather obviously perhaps to use a standard library reference. The definitive reference is the ISO standard. But there are others The Dinkumware C Library for example.


I'm sure that at least atoi() is in the std library.

Wikipedia confirms it atoi() itoa()


itoa is not in standard library../


itoa is not part of the standard library; it is a common extension.

atoi is part of the standard library, and its prototype is declared in stdlib.h (n1256, § 7.20.1.2).

For a complete listing of what functions are part of the standard library, see the online C standard, draft n1256, § 7 (Library).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜