The Dink Network

Reply to Re: C Programming Tutorial

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
February 3rd 2006, 12:51 AM
anon.gif
toa
Ghost They/Them
 
void val(string s, int x, int err);
If the chars contained by s were digits, then x would become the number value contained in s. If not, the err varaible would indicate the position of the first non-digit char.
Is anything similar in C? Can you indicate me a good tutorials about strings, in C?


strtol() or strtoul()

They're in either stdlib.h or string.h (I forget which).

If you want error checking:

errno = 0;
myval = strtol(s,NULL,0);
if (errno) { /*error-handling goes here*/; }

As for tutorials on strings in C:

Rule 1: Don't use string.h.
Rule 2: Don't use char* as a string type.
Rule 3: Find a good dynamic string library.

Rule 3 gives you your tutorial, since any good string lib will have documentation.