"Christmas - the time to fix the computers of your loved ones" « Lord Wyrm

pointer übungsbeispiel (C)

davebastard 29.09.2004 - 19:24 755 9
Posts

davebastard

Vinyl-Sammler
Avatar
Registered: Jun 2002
Location: wean
Posts: 11549
also..hab da einen Fehler bei der ausgabe des variablentyps double
hier der code:
Code:
#include <stdio.h>
#include <conio.h>

int main (void)
{
    char Arrayc[10],*pArrayc;
    int x,Arrayi[10],*pArrayi;
    double Arrayd[10],*pArrayd;
    
    pArrayc = Arrayc ; 
    pArrayi = Arrayi ;
    pArrayd = Arrayd ;
    for (x=0;x<10;x++)
        {
        *(pArrayc+x) = 'a';
        *(pArrayi+x) = 3;
        *(pArrayd+x) = 9;
        }
    
    printf("WERT         ADRESSE \n");
    for (x=0;x<10;x++)
        {
        printf ("%c   %x \n",*(pArrayc+x),(pArrayc+x));
        }
    for (x=0;x<10;x++)
        {
        printf ("%d   %x \n",*(pArrayi+x),(pArrayi+x));
        }
    for (x=0;x<10;x++)
        {
        printf ("%ld  %x \n",*(pArrayd+x),(pArrayd+x));
        }
    
    getch();
    return 0;
}

gut und jetzt die Ausgabe:
Code:
WERT         ADRESSE
a   22ff68
a   22ff69
a   22ff6a
a   22ff6b
a   22ff6c
a   22ff6d
a   22ff6e
a   22ff6f
a   22ff70
a   22ff71
3   22ff28
3   22ff2c
3   22ff30
3   22ff34
3   22ff38
3   22ff3c
3   22ff40
3   22ff44
3   22ff48
3   22ff4c
0  40220000
0  40220000
0  40220000
0  40220000
0  40220000
0  40220000
0  40220000
0  40220000
0  40220000
0  40220000

in den letzten 10 zeilen sollte doch jeweils 9 und dann die Adresse stehen :confused:
"%ld" zum ausgeben von double stimmt aber schon oder nicht ?
kann mir jemand helfen?
Bearbeitet von davebastard am 29.09.2004, 19:57

void0

Little Overclocker
Avatar
Registered: Dec 2002
Location: at/wien/4 | ch@I..
Posts: 58
Zitat von davebastard
"%ld" zum ausgeben von double stimmt aber schon oder nicht ?
kann mir jemand helfen?

%f ist der richtige Code für double. %ld ist für 64bit Integer iirc.

davebastard

Vinyl-Sammler
Avatar
Registered: Jun 2002
Location: wean
Posts: 11549
danke jetzt funktionierts ;)
Trotzdem ist die Ausgabe jetzt mit komma
Code:
 
9.000000  22fec8
9.000000  22fed0
9.000000  22fed8
9.000000  22fee0
9.000000  22fee8
9.000000  22fef0
9.000000  22fef8
9.000000  22ff00
9.000000  22ff08
9.000000  22ff10

gibts da nicht ne andere möglichkeit?
ich dachte immer double hat nur ganze Zahlen :confused:

mat

Administrator
Legends never die
Avatar
Registered: Aug 2003
Location: nö
Posts: 25377
int ist ua für ganze zahlen. kommt aber auch auf deinen parameter bei printf an.

davebastard

Vinyl-Sammler
Avatar
Registered: Jun 2002
Location: wean
Posts: 11549
ja ich weiß aber ich muß double verwenden, is leider bei der aufgabenstellung so :( .
Kann man die Ausgabe von double nicht so formatieren das das komma und die Nullen weg sind ?

ica

hmm
Avatar
Registered: Jul 2002
Location: Graz
Posts: 9802
Zitat von mat
int ist ua für ganze zahlen. kommt aber auch auf deinen parameter bei printf an.

und auf was solls da drauf ankommen? int ist für ganze zahlen, da können auch deine parameter nix ändern (außer du meinst die formatierung damit nachstehende 0 angezeigt werden)

ica

hmm
Avatar
Registered: Jul 2002
Location: Graz
Posts: 9802

davebastard

Vinyl-Sammler
Avatar
Registered: Jun 2002
Location: wean
Posts: 11549
thx

die richtige Zeile,falls es jemanden interessiert,lautet:
Code:
 printf ("%.f   %x \n",*(pArrayd+x),(pArrayd+x));

void0

Little Overclocker
Avatar
Registered: Dec 2002
Location: at/wien/4 | ch@I..
Posts: 58
double ist halt denkbar ungeeignet für das was du da tust :)

davebastard

Vinyl-Sammler
Avatar
Registered: Jun 2002
Location: wean
Posts: 11549
Zitat
ja ich weiß aber ich muß double verwenden, is leider bei der aufgabenstellung so .

wie schon gesagt es handelt sich um ein übungsbeispiel,klar dass es keinen sinn macht
Kontakt | Unser Forum | Über overclockers.at | Impressum | Datenschutz