daily pastebin goal
89%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Aleksi Kuznetsov, 0508819, 13.2.2018*/
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. void do_change(int *pnumbers);
  7.  
  8. void do_print(int *pnumbers);
  9.  
  10. int main(void)  {
  11.  
  12.   int do_this;
  13.   int numbers[0];
  14.   int *pnumbers = numbers;
  15.   int amount = 0;
  16.   int *pamount = &amount;
  17.  
  18.   while (1) {
  19.     printf("%d) Tulosta taulukon alkiot\n%d) Muuta taulukon kokoa\n%d) Lopeta\n", 1, 2, 0);
  20.     printf("Anna valintasi: \n");
  21.     scanf("%d\n", &do_this);
  22.  
  23.     if (do_this == 1) {
  24.         do_print(numbers);
  25.     } else if (do_this == 2) {
  26.         do_change(numbers);
  27.     } else if (do_this == 0) {
  28.         break;
  29.     }
  30.   }
  31.  
  32.   printf("Kiitos ohjelman käytöstä.\n");
  33.   free(pnumbers);
  34.   pnumbers = NULL;
  35.  
  36.   return 0;
  37. }
  38.  
  39. void do_change(int *pnumbers) {
  40.  
  41.   printf("Anna taulukon uusi koko: \n");
  42.   scanf("%d\n", &amount);
  43.  
  44.   pnumbers = malloc(amount*sizeof(int));
  45.  
  46.   if (pnumbers == NULL) {
  47.       perror("rip");
  48.       exit(1);
  49.   } else {
  50.       for (int i=0; i<amount; i++)
  51.         pnumbers[i] = i;
  52.   }
  53. return;
  54. }
  55.  
  56. void do_print(int *pnumbers) {
  57.   for (int i=0; i<amount; i++)
  58.      printf("%d ", pnumbers[i]);
  59. return;
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top