Solved

# function STRTOL

Posted on 2004-10-01
230 Views
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
Question by:matthew016

LVL 84

Accepted Solution

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

LVL 9

Expert Comment

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

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

## Featured Post

### 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 is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.