For many purposes, i need to take a large input of string.
I have declared a character array in large size. But i cannot take
more than 128 characters input as string from keyboard.
Can anyone help me about htis problem ?
-TUHIN
String Input
Moderator: Board moderators
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
u can try this for reading a line of unlimited size, with dynamic allocation:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
const int BLOCK = 16;
char *getline(void) {
char *p, *s = NULL;
int c, lim = -1, size = 0;
while ((c = getchar()) != EOF) {
if (size >= lim)
if (!(p = realloc(s, (lim+=BLOCK)+1))) {
ungetc(c, stdin);
break;
} else s = p;
if ((s[size++] = c) ==
Understanding a problem in a natural way will lead to a natural solution