thespeedracer38

Static Array of Strings

May 11th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #define MAX_NAMES 100
  2. #define MAX_BUFFER_CAP 512
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6.  
  7. int main(void)
  8. {
  9.     char names[MAX_NAMES][MAX_BUFFER_CAP];
  10.     int size, i;
  11.     clrscr();
  12.     printf("How many names do you want to store\n(Should be less than 100)? ");
  13.     scanf("%d", &size);
  14.     fflush(stdin);
  15.     for(i = 0; i < size; i++)
  16.     {
  17.         printf("Enter name %d: ", i+1);
  18.         gets(names[i]);
  19.     }
  20.     printf("The names are\n");
  21.     for(i = 0; i < size; i++)
  22.     {
  23.         printf("%s\n", names[i]);
  24.     }
  25.     free(names);
  26.     getch();
  27.     return 0;
  28. }
Add Comment
Please, Sign In to add comment