function STRTOL

Posted on 2004-10-01
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 :-)*
Question by:matthew016
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 84

Accepted Solution

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

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.




Author Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures 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.

728 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