Bill Cunningham said:
THanks for the wake up Dan. It would have to be that simple. Here's the
code I wrote though because puts was wanting a cast.
No, puts doesn't want a cast. If you're casting an argument to
puts(), you're almost certainly doing something wrong. Remove the
cast, read the error message, and find some other way to fix it.
#include <stdio.h>
int outtext(char *buffer)
{
printf("%s",*buffer);
return 0;
}
*buffer is of type char. printf with "%s" expects a char*. You're
not getting an error message because printf is a variadic function;
its prototype can't specify the types of all the arguments because
their types can vary depending on the format string (which isn't
necessarily a literal).
This:
printf("%s", buffer);
is correct; "%s" tells printf to expect a char*, and buffer is of type char*.
I suspect you tried something like this:
int outtext(char *buffer)
{
puts(*buffer);
return 0;
}
and got an error message. The solution is to change the puts call to:
puts(buffer);
Again, I think you're trying to use these functions without checking
their documentation. puts() doesn't expect a char, it expects a
char*. If you're not certain what it expects, you should look it up
before you write the call.
Also, note that
printf("%s", buffer);
and
puts(buffer);
are not equivalent. As your documentation will tell you, puts appends
a new-line to the string when it prints it. If you don't want the
new-line, you can use
fputs(buffer, stdout);
which *doesn't* append a new-line.
This difference in behavior between puts and fputs is, as far as I can
tell, entirely arbitrary, and it's one more demonstration of why you
should always read the documentation before trying to use any
function.