[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] char til int



----- Original Message ----- 
From: <sslug@sslug>
> Kære c-liste,
> 
> Hvordan kan jeg convertere enkelte char i et char-array til integers (0
> eller 1)? -Eller kan man erklære et bit-array i c?

Du havde næsten gjort det rigtigt, men for at få 1 eller 0 ud af det skal du trække '0' fra. Se kode:

main()
{
    char* s= "0110";

    while(*(s++))
        insert_int(*s - '0');
}

der er ikke nogen datatype der hedder bit i C.

> Nedestående løsning giver ASCII koden, der så vidt jeg har forstået er
> maskinafhængig.

Nej -- ASCII er ikke maskinafhængig, det er en standart.

/Kasper

- - - - - -
Get PGP key from www.keyserver.net - Key ID: 0xDE21F438
Name = Kasper Bonne
Fingerprint = B583 0E69 166A 15EF B6F8 B248 7558 DB7C DE21 F438 
- - - - - -


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