1.
Code:
fgets(input, MAX, stdin);
length = stringLength(input);
...
int stringLength(char str[])
{
int i = 0;
for(i=0; i<MAX; i++)
{
if(str[i ]=='\n')
return i;
}
return i;
}
fgets will store at most 49 meaningfull characters (reserving the 50th one for the NULL terminating character) meaning that the maximum string length for something stored in input should be 49. Your stringLength function however will currently return 50 as the length for such a string.
It might just be better to use strlen on the input array (not calling stringLength at all) and then check if the last character is a newline or not and change it to a NULL if it is (also adjusting the length by -1):
Code:
fgets(input,MAX,stdin);
length = strlen(input);
if(length > 0 && input[length-1] == '\n')
{
input[length-1] = '\0';
--length;
}
2.
Code:
for(i=0;i<=length;i++)
{
temp[i ] = input[i ];
}
Why? Just use strcpy instead, that's what it is there for.
3.
Code:
char store[MAX]; //longest string stored here
...
int maxLength = strlen(store);
...
if(length>=maxLength)
{
maxLength gets set to some indeterminate size at the beginning of the program. The array store can have random junk in it and strlen(store) may return anything from 0 on up. You probably want to set maxLength to MAX initially.