/**************************
Formatted input:
scanf(format_string, pointer_args)

Example:
{ int a, *bp;
  char c[81];
  scanf("%d %d %s", &a, bp, c);  // read string of non-white-space into c
}

Unformatted input:
Reading a line into a character string in memory for further processing:
see read_line() below.

**************************/

#include <stdio.h>

/*** k = read_line(S, n);
 S must be an array of at least n chars.  n must be nonnegative.
 Read a line of chars from stdin into S (and make it null terminated),
 but read at most n chars so as not to overflow S.
 Returns: actual number of chars put in string.  Thus,
 if k is returned, S[0]..S[k-1] is the string; S[k] is the null character.
***/
int read_line(char *string, int n);

int main(){
  int a, b;
  int *bp = &b;
  char c[81], d[81], e[81];

  // read a sequence such as "3 -5  hello,bye " (possibly on multiple lines)
  scanf("%d %d %s \n", &a, bp, c);  // read string of non-white-space into c
  // makes c a null terminated character sequence.

  // read a single line of at most 80 chars.
  scanf("%s\n", d);
  // Oops...
       
  // read a single line of at most 80 chars.
  read_line(e,80);
  // :-)

  printf("%d %d\n", a, b);
  printf("%s\n", c);
  printf("%s\n", d);
  printf("%s\n", e);
	
}

int read_line(char *string, int n) {
  int i; char ch;
  for ( i = 0, ch = getc(stdin); // init
        i < n && ch != '\n';    // continuation condition
	    ++i, ch = getc(stdin)    // update
	  ) {
     string[i] = ch; 
  }
  string[i] = 0;
  // makes string a null terminated character sequence.
  return i;
}

