Skip to content

Instantly share code, notes, and snippets.

@jboockmann
Last active February 17, 2019 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jboockmann/e2ffb6d821f71b2215bf0751618d09f5 to your computer and use it in GitHub Desktop.
Save jboockmann/e2ffb6d821f71b2215bf0751618d09f5 to your computer and use it in GitHub Desktop.
multarraycopy.c
$ gcc -Wall -Werror multarraycopy.c
$ ./a.out
[0] => 2
[1] => 4
[2] => 6
[3] => 8
[4] => 10
#include <stdio.h>
#include <stdlib.h>
int *multarraycopy(int scal, int *feld, int max)
{
int *feldNeu = malloc(max * sizeof(int));
for (int i = 0; i < max; i++)
{
feldNeu[i] = feld[i] * scal;
}
return feldNeu;
}
int main(void)
{
int feld[] = {1, 2, 3, 4, 5};
int max = 5;
int scal = 2;
int *feldNeu = multarraycopy(scal, feld, max);
for (int i = 0; i < max; i++)
{
printf("[%d] => %d\n", i, feldNeu[i]);
}
return 0;
}
Copy link

ghost commented Jan 23, 2019

Hallo, ist das nicht zufälligerweise die Aufgabe?
"multarraycopy soll eine Zahl scal und ein Feld feld unter der Annahme, dass dieses im Hauptprogramm korrekt mit max Elementen angelegt und initialisiert wurde, als Eingabe nutzen, intern kopieren, alle Elemente mit dem Wert scal multiplizieren und als Ergebnis die geänderte Kopie zurückgeben ohne das Original zu verändern."

@jboockmann
Copy link
Author

Ja, sieht danach aus ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment