473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

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("\nBeispiel:");
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
4 8624
Zahpod wrote:

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

Should be atoi?

--
Ian Collins.
Apr 21 '06 #2
"Zahpod" <Ro*********@gmail.com> 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>.

Richard
Apr 21 '06 #3
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)

NAME
stoi, numtos - convert between an integer and a decimal
string

SYNOPSIS
#include <sys/ddi.h>

int stoi(char **str);

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

INTERFACE LEVEL
Solaris DDI specific (Solaris DDI).

PARAMETERS
str Pointer to a character string to be converted.

num Decimal number to be converted to a character
string.

s Character buffer to hold converted decimal number.

DESCRIPTION
stoi()
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
examined.

numtos()
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
Hi Richard
Many thanks, your and Ian's answers helped!
Have a nice weekend! :)

Apr 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Will | last post by:
Pardon two post in a row to the newsgroup but I want to try and expedite this, if you guys don't mind helping out... I running Windows XP Pro and wanted to download Python and any additional...
4
by: blah | last post by:
I m actually a Novice in Python as well as Linux, When i look up things on the internet about Linux Flavours, They are written so complex that it is difficult for me to understand, i am asking if...
4
by: Eggnog | last post by:
Hi, Is there a newsgroups for beginners questions? Cheers, Nawg
24
by: Charles Ulrich | last post by:
Greetings, I hope my greenness isn't showing too bad by asking this, but I ran across this trivial program today that left me flabbergasted: #define MESSAGE "This account is currently not...
6
by: William Foster | last post by:
Does anyone know of a good online tutorial for C# focused on beginners. I have been to many great sites like csharpfriends, csharp-corner etc looking for good tutorials and have had no luck. Any...
3
by: baibaichen | last post by:
hi, i am reading a C++ book, it mentions a term non-trivial object. what i understand is: if a object has: a) trivial constructor b) trivial assignment operator c) trivial destructor then it...
4
by: aman firoz | last post by:
do you people got anything for c beginners..... help me out guys
19
by: yltkhuu | last post by:
1. How does having a widely adopted C++ standard help game programmers? 2. What are the advantages ans disadvantages of employing the "using" directive? 3. Why might you define a new name for an...
6
by: Lars | last post by:
Hi all If this is the wrong list for beginners trouble I apologize. please refer to me the correct list in such case. I am trying to create a simple linked list but I keep getting segmentation...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.