home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / EXAMPLES.ZIP / INTRO27.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  515 b   |  23 lines

  1. /* INTRO27.C--Example from Chapter 4 of Getting Started */
  2.  
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7.    char string[80];              /* Has 79 usable elements */
  8.    char number[10];
  9.    int pos, num_chars;
  10.  
  11.    printf("Enter a string for the character array: ");
  12.    gets(string);
  13.    printf("How many characters do you want to extract? ");
  14.    gets(number);
  15.    sscanf(number, "%d", &num_chars);
  16.  
  17.    for (pos = 0; pos < num_chars; pos++)
  18.       printf("%c", string[pos]);
  19.    printf("\n");
  20.  
  21.    return 0;
  22. }
  23.