Your first major problem is that your validate() function is returning a string that you haven't initialized. The only place valid_input is even used in that function is the definition at the top of the function and the return statement. The validate() function really doesn't even need to return anything at all. You're modifying the valid string inside the function and it will persist in the calling function. You'd have to change the way you call validate() since it wouldn't be returning a value anymore, obviously.
Code:
for (k=0; k<length; k++)
{
if (valid[k] == '\n')
{
valid[k] = '\0';
length--;
}
}
What if the '\n' isn't right before the '\0'? Your length will be off. That loop might better be written as:
Code:
for(k = 0;valid[k] != '\0';++k)
{
if(valid[k] == '\n')
{
valid[k] = '\0';
length = k;
break;
}
}
Or better yet, let the standard library do the work for you:
Code:
char *p;
if((p = strchr(valid, '\n')))
{
*p = '\0';
length = p - valid;
}
Of course, length really isn't necessary if you change your loop conditions to just check if valid[index] is equal to '\0'.
Code:
printf("valid_1 is %c\n", valid_1);
valid_1 is defined as a char * and should not be printed using the %c format specifier. Use %s to print strings.
Code:
printf("Please enter input 1.\n");
input_1 = fgets(buffer1, 256, stdin);
valid_1 = validate(input_1);
Why even have input_1? You can just do this:
Code:
fgets(buffer1, 256, stdin);
valid_1 = validate(buffer1);