Yes its working thanks a lot to all the guys at the forum.
>> remove the 'char *' -- it is hiding the other variable
Just wanted to know wat is the meanig of this stmt
I thought that i would post the working and clean code so that someone can refer to this for learing the string legth funcitons.
#include <stdio.h>
#include <stdlib.h>
int strlength ( char input[] )
{
int count = 0;
while ( input[count] != '\0' )
++count;
return count;
}
int main(void)
{
int ch, index = 0;
char *input = 0;
char inputBuffer;
while ((ch = getchar()) != '\n' && ch != EOF);
fputs ("Enter some text: ", stdout);
while ((inputBuffer = getchar()) != '\n')
{
input = (char*) realloc (input, index + 2);
if (input == NULL)
{
fputs("Memory allocation error", stderr);
exit(1);
}
else
{
input[index++] = inputBuffer;
}
}
input[index] = '\0';
printf("The length of the string is %d", strlen(input));
return 0;
}
Thanks again Narue and Dragon.