retrogamer

Dynamic 2D Array String

Jan 1st, 2021
294
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.      int i,n;
  7.      char (*name)[n]= malloc(sizeof(int[i][n]));
  8.  
  9.      printf("Enter the number of names (<10): ");
  10.      scanf("%d",&n);
  11.  
  12.      for(i=0; i<n; i++){
  13.  
  14.         printf("Enter %d names: ",i+1);
  15.         scanf("%s[^\n]",name[i]);
  16.  
  17.      }
  18.      for(i=0;i<n;i++){
  19.  
  20.         printf("\nEntered names are:");
  21.         printf("%s",name[i]);
  22.  
  23.      }
  24.  
  25.      free(name);
  26.  
  27.      return 0;
  28. }
RAW Paste Data