[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] argv[] problem...



Jeg har to kommentarer (til Björn Tillenius iøvrigt meget præcise svar):

ad 1). konvertering fra char[] til <unsigned?>int
funktionen int atoi(.) ser ud til til at blive "depreciated" --- dvs. at vi
ikke kan regne med at funktionen understøttes i fremtiden, brug istedet:

long strtol(const char *s, char **endp, int base);  /* erklæret i stdlib.h*/
/* læs *info* Libc for betydningen af parametre */
til konvertering fra char* til int famillien


ad 2). konvertering fra signed(sic!) int til char*
funktionen:
char* itoa(int value, char *string, int radix);  /* erklæret i stdlib.h */
lover at kunne klare den modsatte konvertering
--- hvorvidt itoa(.) er ANSI C eller lider samme kranke skæbne som atoi(.)
har jeg skam at melde ikke fået undersøgt.

C U
Nils Åke Ljunggren
sslug@sslug
http://home12.inet.tele.dk/ngr


Björn Tillenius skrev:

> > Hejsan!!
> >
> > Jag håller på med ett enkelt program (mest för att lära mig mer C) och
> > nu undrar jag en sak:
> > Mitt program som ska kräva ett argument. Detta argumentet ska vara ett
> > positivt int-tal.
> > Hur gör jag för att göra om argv[1] till en int som jag sedan kan lagra
> > i en vanlig int-variabel??
> tal = atoi(argv[1]);
>
> >
> > (Och kan även, senare, göra om ett argument till en char-variabel.)
> Det är lite krångligare, det finns inte någon sådan
> funktion i ANSI C (eller?). Men du kan använda sprintf:
> sprintf(buf,"%i",tal);
>
> där buf är en pekare till en char-array.
> >
> > (Det är C, och inte C++ alltså)
> >
> > --
> >  ============================= LINUX ==============================
> > ||  Name:      Johan Andersson   |  Icq-Uin:   28572735           ||
> > ||  E-mail:    sslug@sslug |  Phone:     +46 (0)417 31150   ||
> >  ==================== The source is out there =====================





 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 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] *