By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,639 Members | 2,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,639 IT Pros & Developers. It's quick & easy.

how to use stoi? which *.h to use? trivial beginners problem...

P: n/a
Hi all

The Code:
#include <stdio.h>
#include <sys/ddi.h>

main(int argc, char *argv[])
int i,dec;
if ( argc < 2 )
printf("\nBitte eine oder mehrere Zahlen als Argument angeben!");
printf("\n %s 10 1 12 132\n",argv[0]);
return 2;

for (i=1; i<argc; i++)
dec = stoi(argv[i]);
printf("%s = %4d = %4x\n", argv[i], dec, dec);
//printf("%s\n", argv[i]);

return 0;

The problem:
$ gcc dec2hex.c
Undefined first referenced
symbol in file
stoi /var/tmp//ccepw0WS.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

Apr 21 '06 #1
Share this Question
Share on Google+
4 Replies

P: n/a
Zahpod wrote:

for (i=1; i<argc; i++)
dec = stoi(argv[i]);

Should be atoi?

Ian Collins.
Apr 21 '06 #2

P: n/a
"Zahpod" <Ro*********> wrote:
#include <stdio.h>
#include <sys/ddi.h>
This header does not exist in ISO C.
dec = stoi(argv[i]);

Neither does this function.

From context I suspect you meant the atoi() function, which is declared
in <stdlib.h>. I suggest, however, that you use strtol() instead. It has
better error handling, which can be important with data you get
unfiltered from your user. For example, atoi() has undefined behaviour
on overflow; strtol() does not. strtol() is also in <stdlib.h>.

Apr 21 '06 #3

P: n/a
1000x thanks, that was it!

I mixed up stoi with atoi.

Cause: Under Solaris 8 or 10 "man stoi" shows:

Kernel Functions for Drivers stoi(9F)

stoi, numtos - convert between an integer and a decimal

#include <sys/ddi.h>

int stoi(char **str);

void numtos(unsigned long num, char *s);

Solaris DDI specific (Solaris DDI).

str Pointer to a character string to be converted.

num Decimal number to be converted to a character

s Character buffer to hold converted decimal number.

stoi() returns the integer value of a string of decimal
numeric characters beginning at **str. No overflow checking
is done. *str is updated to point at the last character

numtos() converts a long into a null-terminated character
string. No bounds checking is done. The caller must ensure
there is enough space to hold the result.

Apr 21 '06 #4

P: n/a
Hi Richard
Many thanks, your and Ian's answers helped!
Have a nice weekend! :)

Apr 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.