Skip to content

Instantly share code, notes, and snippets.

@Snawoot
Created July 20, 2013 21:30
Show Gist options
  • Save Snawoot/6046483 to your computer and use it in GitHub Desktop.
Save Snawoot/6046483 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define MAXLINE 1000 /* max size of input string */
char rev[MAXLINE];
int getlline(char [], int);
void copy(char [], char []);
char* reverse(char []);
/* print the longest string */
void main()
{
// int len; /* input string length */
char storage[MAXLINE]; /* for strings which size is more than 8 symbols*/
getlline(storage, MAXLINE);
puts(storage);
//
// int max; /* longest string length */
// char line[MAXLINE]; /* input string */
// char longest[MAXLINE]; /* longest string */
// // printf("%s\n", line[MAXLINE].length());
// max = 0;
// while ((len = getlline(line, MAXLINE)) > 0) {
// if (len > max) {
// max = len;
// copy(longest, line);
// }
// if (len >= 8) {
// copy(storage, line);
// }
// }
// if (max > 0) /* any string at all? */
// puts("Lognest: ");
// printf("%s\n", longest);
// puts("In Storage: ");
// printf("%s\n", storage);
// puts("Reversing Last String: ");
// printf("%s\n", reverse(storage));
// return 0;
}
/* getlline: read string to s, return length*/
// int getlline(char s[], int lim)
// {
// int c, i;
// for (i = 0; i < lim-1 && (c = getchar()) != EOF && c != '\n'; ++i)
// s[i] = c;
// if (c == '\n') {
// s[i] = c;
// ++i;
// }
// s[i] = '\0';
// return i;
// }
int getlline(char s[], int lim)
{
int c,i=0;
while ((c = getchar())!= EOF){
if (i < lim-1){
if (c != '\n'){
s[i] = c;
i++;
}
}
}
if (c == '\n'){
s[i] = c;
i++;
}
s[i] = '\0';
return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment