Δημοσιεύτηκε: 24 Φεβ 2012, 02:01
- Μορφοποιημένος Κώδικας: Επιλογή όλων
-
char *s_getany( int chunklen )
{
int i = 0; /* char counter */
char *s = NULL, *try = NULL;
/* sanity checks */
if ( chunklen < 1 || NULL == (s = calloc( chunklen+1, sizeof(char)) ) )
return NULL;
for (i=0; EOF != (s[i] = getchar()) && s[i] != '\n'; i++)
{
if ( i != 0 && i % chunklen == 0 ) /* needs realloc */
{
try = realloc(s, (i+chunklen+1) * sizeof(char) );
if ( !try ) { /* realloc failed */
free(s);
s = NULL;
return NULL;
}
s = try; /* accept realloc */
}
}
s[i] = '\0';
if ( NULL == (try = realloc(s, (i+1) * sizeof(char) )) )
return NULL;
return try;
}
Για τεστάρετε το bbcode (Το έχω βάλει δοκιμαστικά μόνο στο θέμα pro_ubuntu_lucid )
- Κώδικας: Επιλογή όλων
[z_code][/z_code]
Αν υπάρξει bug ενημερώστε