ma******@hotmai l.com writes:
process_word("t est");
process_word("t est1");
process_word("t est2");
-tells that function is working
You didn't quote any context from the previous articles in this
thread. Someone reading your latest article without seeing the rest
of the thread isn't going to have any idea what process_word is
supposed to do, or how "word" is declared. Please quote enough
context so that your article makes sense on its own.
printf("%s\n",& word);
-tells that loop have access to every word on file individually
From your previous description, word is declared as
char word[50];
so &word is a pointer to array of char, of type "char(*)[50]".
printf's "%s" format expects a char*, not a pointer to an array. The
above is very likely to work anyway, but the correct call is
printf("%s\n", word);
(This assumes that word contains a string, i.e., a sequence of
characters terminated by '\0'.)
So now, when I try to combine these features to call function on every
word on file, it fails either on syntax error or if it get past
compiler function does not work properly.
So some things you tried resulted in syntax errors (that you haven't
shown us), and other things you tried resulted in code that "does not
work properly" in some manner that you haven't bothered to tell us,
and you haven't told us which is which.
If you show us your actual code, we can be of more help. By "actual
code", I mean a complete compilable and executable program.
Copy-and-paste the exact source file that you fed to the compiler;
don't try to re-type it. Tell us what it does, what you expected it
to do, and how those two things differ.
I figured that easiest way to make it work is make my function work
like printf();
So I need to call inside loop
process_word("% s\n",&word);
Yet need to be solved how printf() is described and change
void processword(cha r *input);
introduced same way.
Based on what you told us so far, I seriously doubt that making your
process_word function behave like printf is going to be useful.
printf uses a fairly complicated mechanism that allows it to handle
variable numbers of arguments of various types. In every example
you've shown us so far, processword processes a single string.
So, given that you've declared "word" as:
char word[50];
I'm reasonably sure that your process_word function needs to look like
this:
void process_word(ch ar *input)
{
/* ... */
}
and any calls should look like this:
process_word(wo rd);
Although "word" is declared as an array, you're actually passing a
pointer to process_word. Read section 6 of the comp.lang.c FAQ,
<http://www.c-faq.com/>, to understand what's going on. Please read
and try to understand the entire section. C's treatment of pointers
and arrays can be very confusing, but the underlying principles are
fairly straightforward ; section 6 of the clc FAQ does an excellent job
of explaining them.
--
Keith Thompson (The_Other_Keit h)
ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"