Solved

function STRTOL

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
negation in C function 14 144
why "." vs "->" 23 119
Need example 5 107
valid enum? 6 73
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

895 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

11 Experts available now in Live!

Get 1:1 Help Now