Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created April 18, 2015 11:08
Show Gist options
  • Select an option

  • Save tomcha/1fc44e39b02ead8cd339 to your computer and use it in GitHub Desktop.

Select an option

Save tomcha/1fc44e39b02ead8cd339 to your computer and use it in GitHub Desktop.
2-2
#include <stdio.h>
#define MAXCHARS 1000
void getlined(char s[], int lim);
int main(){
char s[MAXCHARS];
getlined(s, MAXCHARS);
printf("%s\n", s);
}
void getlined(char s[], int lim){
int i;
int c;
// for(i=0; i< lim - 1 && (c = getchar()) != '\n' && c != EOF; i++){
for(i=0; !(i>= lim - 1 || (c = getchar()) == '\n' || c == EOF); i++){
s[i] = c;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment