[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



Tak for hjælpen igen!

- Jesper

"Søren H. Sørensen" <sslug@sslug> wrote in message
news:sslug@sslug
> På et tidspunkt brugte jeg tallet 123.
>
> Når det bliver til integer vil det i en 32-bits maskine binært hedde:
> 00000000000000000000000001111011
>
> atoi laver tallet om til dette, mens printf kan lave det om til
> mennesketallet 123 igen.
>
> Søren
>
> Jesper wrote:
> >
> > Ok end of story...
> >
> > det ville jeg nemlig oxe mene... det har netop forvirret mig en del al
det
> > der....
> >
> > men tak for hjælpen og så jeg ik jeg ska spørge om mere... kan jeg høre
:)
> >
> > - Jesper
> >
> > "Søren H. Sørensen" <sslug@sslug> wrote in message
> > news:sslug@sslug
> > > Helt ærligt - kender du det mindste til datatyper og deres
> > > repræsentation?
> > >
> > > I nedenstående program er det inderligt ligemeget med at bruge atoi,
men
> > > det vil da virke. Vi bruger ikke gets-funktionen, for den er farlig og
> > > kan medføre smadring af program og data-områder. Vi bruger fgets, hvor
> > > vi kan begrænse antallet af tegn.
> > >
> > > Programmet er tåbeligt, for det læser tal ind som tengstreng,
> > > konverterer dem til integers og siden lader man printf konvertere dem
> > > til tegnstreng igen. Man kunne lige så godt skrive strengene ud med
> > > %s......
> > >
> > > Søren
> > >
> > > Jesper wrote:
> > > >
> > > > #include <stdio.h>
> > > > #include <stdlib.h>
> > > >
> > > > int main()
> > > > {
> > > > int weight;
> > > > int age;
> > > > char weightchar[5];
> > > > char agechar[3];
> > > > printf("How much do you weigh?:\n");
> > > > gets(weightchar);
> > > > weight=atoi(weightchar);
> > > > printf("How old are you?:\n");
> > > > gets(agechar);
> > > > age=atoi(agechar);
> > > >
> > > > printf("So you are %i years old and weigh %i, Man you are OLD AND
> > > > FAT!\n",age ,weight);
> > > > }
> > > >
> > > > Det her er fra en tutorial
> > > >
> > > > jeg forstårbare ikke hvilken nytte atoi så gør i det her eksempel...
> > > >
> > > > er det hvis brugeren fx skriver "about 65 kilos" eller hva?
> > > >
> > > > "Jesper" <sslug@sslug> wrote in message
> > > > news:sslug@sslug
> > > > > Ok hvorfor 0 ved abc123???
> > > > >
> > > > > Og vil det sige hvis jeg skriver et kommatal laver atoi det om til
> > > > nærmeste
> > > > > hele tal??
> > > > > "Henrik Witt-Hansen" <sslug@sslug> wrote in message
> > > > > news:sslug@sslug
> > > > > > Hi.
> > > > > >
> > > > > > > funktionen atoi hvad gør den egentligt?? Sikrer at en
> > > > > > > given input ER en integer eller??
> > > > > >
> > > > > > Konverterer den del af en streng som er et tal, til et tal..
> > > > > >   ehem. altså....
> > > > > >
> > > > > >
> > > > > >
> > > > > > #include <stdio.h>
> > > > > > #include <stdlib.h>
> > > > > > #include <unistd.h>
> > > > > > int main()
> > > > > > {
> > > > > >   char string1[]="123abc";
> > > > > >   char string2[]="abc123";
> > > > > >   char string3[]="abc";
> > > > > >   char string4[]="123";
> > > > > >   printf("%s: %d\n",string1,atoi(string1));
> > > > > >   printf("%s: %d\n",string2,atoi(string2));
> > > > > >   printf("%s: %d\n",string3,atoi(string3));
> > > > > >   printf("%s: %d\n",string4,atoi(string4));
> > > > > >   return 0;
> > > > > > }
> > > > > >
> > > > > >
> > > > > > output:
> > > > > >
> > > > > > 123abc: 123
> > > > > > abc123; 0
> > > > > > abc: 0
> > > > > > 123: 123
> > > > > >
> > > > > >
> > > > > >
> > > > > >    bean
> > > > > >
> > > > >
> > > > >
> > >
>




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