Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
32
Task/Input-loop/C/input-loop.c
Normal file
32
Task/Input-loop/C/input-loop.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char *get_line(FILE* fp)
|
||||
{
|
||||
int len = 0, got = 0, c;
|
||||
char *buf = 0;
|
||||
|
||||
while ((c = fgetc(fp)) != EOF) {
|
||||
if (got + 1 >= len) {
|
||||
len *= 2;
|
||||
if (len < 4) len = 4;
|
||||
buf = realloc(buf, len);
|
||||
}
|
||||
buf[got++] = c;
|
||||
if (c == '\n') break;
|
||||
}
|
||||
if (c == EOF && !got) return 0;
|
||||
|
||||
buf[got++] = '\0';
|
||||
return buf;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
char *s;
|
||||
while ((s = get_line(stdin))) {
|
||||
printf("%s",s);
|
||||
free(s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue