Solved

function STRTOL

Posted on 2004-10-01
3
239 Views
Last Modified: 2012-08-13
Hello !
I would like to write the function strtol (char *s, char **pptr, int base)

char * ptr;
char input [80];
long number;

number = strtol(input, &ptr, 10);
if (*ptr == '\0') ...



long strtol (char *s, char **pptr, int base) {

     int i, n = 0;

     for ( i = 0 ; t[i] >='0' && t[i] <= '9' ; ++i )
          n = base * n + ( t[i] - '0');

     ( how can i make here the pointer point at the first letter met in the table ? )

     return n;
}



*sorry, french :-)*
0
Comment
Question by:matthew016
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 100 total points
ID: 12205400
*pptr = &t[i];
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 12205876
What is t[] here?If it is allocated in the function itself,then pointing to the array would be incorrect since it be non-existent once the function ends.

You should make pptr point to the first letter in the original string that was passed.

*pptr=&s[i];

or

*pptr=&(*s);
0
 
LVL 9

Author Comment

by:matthew016
ID: 12206477
Thank You !!
indeed, it was s[] ,not t[]
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question