[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...



> 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] *