Problems with strtol() from <stdlib.h> 
Author Message
 Problems with strtol() from <stdlib.h>

Hello,

I want to convert a string into a long int.
The string of numbers is given as following:

long a;
char inword[256]
fscanf( Datei1, "%s", inword);

For strtol I need refering to the reference the following syntax
a = strtol(char* source; char** end, int basis);
In my cas it's
a = strtol(inword,??,10)

How do I get char** end???

Is there a simplier way for doing this?

Thank you in advance,

Bernd



Mon, 02 May 2005 00:18:22 GMT  
 Problems with strtol() from <stdlib.h>

Quote:
> Hello,
> I want to convert a string into a long int.
> The string of numbers is given as following:
> long a;
> char inword[256]
> fscanf( Datei1, "%s", inword);
> For strtol I need refering to the reference the following syntax
> a = strtol(char* source; char** end, int basis);
> In my cas it's
> a = strtol(inword,??,10)
> How do I get char** end???
> Is there a simplier way for doing this?

The char** end parameter is a pointer to a char* that will store the
location where the conversion ended. You are supposed to already have a
suitable char* and pass its address to char** end.
If you do not need the char** end functionality and wish not to use it
simply pass a NULL pointer (please, regulars, no massive arguments
about the spelling, thanks) as the char** end parameter.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/
"The truth is out there, man! Way out there!"
   - Professor Ashfield



Mon, 02 May 2005 00:31:08 GMT  
 Problems with strtol() from <stdlib.h>

Quote:
> Hello,

> I want to convert a string into a long int.
> The string of numbers is given as following:

> long a;
> char inword[256]
> fscanf( Datei1, "%s", inword);

> For strtol I need refering to the reference the following syntax
> a = strtol(char* source; char** end, int basis);
> In my cas it's
> a = strtol(inword,??,10)

> How do I get char** end???

char *endp;
a = strtol(inword, &endp, 0);

--

"LISP  is worth learning for  the profound enlightenment  experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days."   -- Eric S. Raymond



Mon, 02 May 2005 01:13:09 GMT  
 Problems with strtol() from <stdlib.h>
Quote:

> Hello,

> I want to convert a string into a long int.
> The string of numbers is given as following:

> long a;
> char inword[256]
> fscanf( Datei1, "%s", inword);

> For strtol I need refering to the reference the following syntax
> a = strtol(char* source; char** end, int basis);
> In my cas it's
> a = strtol(inword,??,10)

> How do I get char** end???

end is set by strtol to point to the place where it stopped parsing the input
string (very handy if you are parsing a long line containing several things
and need to track where you are).  If you are not interested in keeping track
of how much of source was successfully parsed by strtol, just pass NULL.
Otherwise, declare a char * variable and pass its address.  Whatever
"reference" you are using should give you atleast this basic information about
strtol.

-nrk.



Mon, 02 May 2005 03:04:30 GMT  
 Problems with strtol() from <stdlib.h>
in comp.lang.c i read:

Quote:
>I want to convert a string into a long int.
>The string of numbers is given as following:

>long a;
>char inword[256]
>fscanf( Datei1, "%s", inword);

construct the fscanf safely, e.g.,

  if (1 != fscanf( Datei1, "%255s", inword ))   /* 255 = sizeof inword - 1 */
  {
    /* cope with problem, e.g., */
    if (ferror(Datei1)) abort();  /* abort on file handling error */
    inword[0] = '\0';             /* else make inword a zero length string */
  }

--
bringing you boring signatures for 17 years



Mon, 02 May 2005 05:51:17 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. <<<<<<<Parsing help, please>>>>>>>>

2. File Format conversion, ascii freeform -->.csv <-->.wk1<-->dbf<-->?HELP

3. <<<>>>Need C code advice with functions and sorting.<<<>>>

4. <><><>HELP<><><> PCMCIA Motorola Montana 33.6

5. book about <stdlib.h>

6. When do you #include <stdlib.h>?

7. Cannot find <stdlib>

8. >>>Windows Service<<<

9. <<Borland C/C++ 5.0 Problem >>!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1

10. What is the use of <stdlib.h> and <math.h>

11. proposal: <basic.h>, <pascal.h>, <fortran.h>, <cobol.h>

12. <<<< C Grammar for yacc needed >>>>

 

 
Powered by phpBB® Forum Software