Guest User

Untitled

a guest
Jun 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define DIM 52
  5.  
  6. void getString( char [] );
  7.  
  8. int main()
  9. {
  10.     char s[DIM];
  11.     printf("Please insert a string ( MAX %d characters ) \n", DIM);
  12.     getString(s);
  13.  
  14.     printf("STRING : %s\n", s);
  15.     /*system("PAUSE"); */
  16.     return 0;
  17. }
  18.  
  19. void getString( char s[] )
  20. {
  21.  
  22.     char c;
  23.     int i = 0;
  24.  
  25.     while( ( c = getchar() ) != '\n' && i < DIM )
  26.     {
  27.         s[i] = c;
  28.         i++;
  29.  
  30.     }
  31.     s[i] = '\0';
  32.  
  33. }
Add Comment
Please, Sign In to add comment