pradyunsg

Untitled

Jan 11th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. int num, i, sum = 0;
  2. char (*ptr)[SIZE];
  3.  
  4. printf("Enter number of elements: ");
  5. scanf("%d", &num);
  6.  
  7. char ptr[num][SIZE];
  8.  
  9. ptr = (char (*)[SIZE]) calloc(num, sizeof(char) * SIZE);
  10.  
  11. if (ptr == NULL) {
  12. printf("Error! Memory not allocated!\n");
  13. exit(0);
  14. }
  15.  
  16. printf("Enter elements...\n");
  17. for (int i = 0; i < num; ++i) {
  18. scanf("%s", ptr[i]);
  19. }
  20.  
  21. printf("Elements are:\n");
  22. for (int i = 0; i < num; ++i) {
  23. printf("%s\n", ptr[i]);
  24. }
Add Comment
Please, Sign In to add comment