aboutsummaryrefslogblamecommitdiff
path: root/1.16.c
blob: 12c9600a5fc0faaf6b3436d18c9194c966f9ec69 (plain) (tree)



















































                                                                            
#include <stdio.h>

#define MAXLINE 1000

int gline(char str[], int len);
void cp_str(char to[], char from[]);

int 
main(void)
{
  int len, max;
  char str[MAXLINE];
  char mstr[MAXLINE];

  max = 0;

  while ((len = gline(str, MAXLINE)) > 0)
    if (len > max) {
      cp_str(mstr, str);
      max = len;
    }

  if (max > 0)
    printf("\nlength: %d\n%s", max, mstr);

  return 0;
}

int 
gline(char str[], int len)
{
  int i;
  char input;
  for (i = 0; i < len-1 && (input = getchar()) != EOF && input != '\n'; i++)
    str[i] = input;

  if (input == '\n' && i < len-1) {
    str[i] = '\n';
    ++i;
  }
  
  str[i] = '\0';

    return i;
}

void
cp_str(char to[], char from[])
{
  for(int i =0; (to[i] = from[i]) != '\0'; i++)
    ;
}