[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] C-programmering i MS Visual Studio



atoi og strtol laver jo nogenlunde det samme, og så vidt jeg husker er
en integer og en long af samme længde på en 32-bit processor.

Jeg har lavet min egen til at læse en time_t ind fra ascii og den ændrer
jeg lige til en atoi/strtol:

int atoi( char *tal )
   {
   int result;
   char *c;
   
   c=tal;  
   result=0;
   while( *c !=0 && *c>=0x30 && *c<=0x39 )
     {
     result *= 10;
     result += *c - 0x30;
     c++;
     } /* while */
   return result;
   }

Denne simple funktion tester ikke på om der ender med at være overløb af
resultatet og denne version kan heller ikke håndtere negative tal, men
det er ret nemt at implementere. Den kan også nemt laves om til en
strtol, hvis man laver "*10" om til en "*radix" og tester på om c
passerer en "end".

M.h.h.
Søren


Nils Åke Ljunggren wrote:
> 
> >Hvis brugeren skriver det er man på den. atoi laver ingen kontrol af
> >input. atoi svarer til at kalde strtol med nogle specielle argumenter,
> >der gør at man ikke laver kontrol af input. atoi bør kun bruges i
> >situationer hvor man ved at input er velformet.
> 
> Jeg har læst i info at atoi skulle være "depreciated".
> På mit system er atoi en makro der kalder strtol.
> 
> Er der nogen der ved hvor jeg finder den nyeste specifikation af
> sprogstandarden til C (ISO/IEC eller ANSI?).
> 
> Med venlig hilsen
> 
> Nils Åke Ljunggren


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *