Solved

function STRTOL

Posted on 2004-10-01
3
230 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now