#include <stdio.h> #define MAXLINE 100 #define MAX 8 int getline(char line[],int maxline); void copy(char to[],char from[]); int main() { int len; int max; char line[MAXLINE] = {0}; char longest[MAXLINE] = {0}; max = 0; while((len = getline(line,MAXLINE)) > 0) { if(len > MAX) { copy(longest,line); } printf("%d %s ",len,longest); } return 0; } int getline(char s[],int lim) { int c,i; for(i = 0; i < lim-1 && (c=getchar()) != EOF && c != ' ';i++) { s[i] = c; } if(c == ' ') { s[i] = c; i++; } s[i] = ' '; return i; } void copy(char to[],char from[]) { int i = 0; while((to[i] = from[i]) != ' ') i++; }
大于8 的字符串输出。