WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   Ausgabe des Programms? (http://www.wcm.at/forum/showthread.php?t=45381)

Bizeps22 05.02.2002 21:41

Ausgabe des Programms?
 
Wer von euch kann mir sagen was folgendes Programm ausgibt.Mein Compiler weigert sich es zu compilieren!Wer kann mir erklären was **s2 (bei Methode func)bedeutet(Pointer auf einen Pointer ?)



#include <stdio.h>
#include <stdlib.h>

void func (char *s1, char **s2, int *z1, int z2);

int main (int argc, char **argv)
{
char *ptr, *list1, *list2;
int i, anz, *zahl;
anz = (int) strtol (argv[1], &ptr, 10);
list1=malloc ((anz+1) * sizeof(char));
list2=malloc ((anz+1) * sizeof(char));

for (i=0;i<anz; i++)
{
list1[i] = *argv[i+2];
list2[anz-i-1] = *argv[i+2];
}

list1[anz]='\0';
list2[anz]='\0';
zahl=&i;

(void) printf ("Liste1: %s, Liste 2: %s, Zahl: %i, Anz: %i\n", list1, list2, *zahl, anz);
func (list1, &list2, zahl, anz);
(void) printf ("Liste1: %s, Liste 2: %s, Zahl: %i, Anz: %i\n", list1, list2, *zahl, anz);
exit (0);
}

void func(char *s1, char **s2, int *z1, int z2)
{
static int wortLaenge = 5;
static char *wort = "Dream";

s1 = wort;
*s2 = wort;
*z1 = wortLaenge;
z2 = wortLaenge;
}

pong 05.02.2002 21:49

>>**s2 (bei Methode func)bedeutet(Pointer auf einen Pointer ?)
genau das

pong 05.02.2002 21:55

ausgabe

Liste1: , Liste 2: , Zahl: 0, Anz: 0
Liste1: , Liste 2: Dream, Zahl: 5, Anz: 0

Bizeps22 05.02.2002 21:59

bist da sicher das für liste1:abcdefg und für liste2:gfedcba rauskommt und für zahl und Anz 7?

Flink 06.02.2002 10:53

Korrektur:

list1= (char *) malloc ((anz+1) * sizeof(char));
list2= (char *) malloc ((anz+1) * sizeof(char));

ACCESS-Violation:

for (i=0;i<anz; i++)
{
list1[i] = *argv[i+2];
list2[anz-i-1] = *argv[i+2];
}


Alle Zeitangaben in WEZ +2. Es ist jetzt 20:27 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag