How would I pass a structure from one function to another?
typedef char word_t[MAX_WORD_LEN+1];
typedef struct {
int nwrds;
word_t words[MAX_PARA_LEN];
} para_t;
int
main() {
para_t onepara;
while (get_paragraph(onepara, MAX_PARA_LEN) != EOF) {
put_paragraph(onepara, MAX_SNIPPET_LEN);
}
end_output();
return 0;
}
int
get_paragraph(para_t p, int limit) {
int d, i;
word_t w;
for (i=0;i<limit;i++) {
if ((d=get_word(w, MAX_WORD_LEN))==EOF) {
return EOF;
} else if(d==WORD_FND) {
strcpy(p.words[i], w);
} else if (d==PARA_END) {
new_paragraph();
break;
}
}
return PARA_FND;
}
void
put_paragraph(para_t p, int limit) {
int i;
for (i=0;i<limit; i++) {
printf("%s\n", p.words[i]);
}
}
I've used strcpy to copy the word 'w' to the array in structure 'p' (in get_paragraph) but when I go to print out that structure, I have trouble getting any output. Currently the put_paragraph outputs no string but I can't figure out why.
The get_word function in get_paragraph works correctly to identify a word and I haven't included it to save space.