I am trying to insert a pattern of letters into a phrase. For example the phrase is dog, cat, bird, tree. I want to have: dog, cat, a, a, bird, tree dog, cat, a, b, bird, tree dog, cat, a, c, bird, tree dog, cat, a, d, bird, tree ... dog, cat, d, c, bird, tree dog, cat, d, d, bird, tree
What I have now prints: dog, cat, a, a, bird, tree dog, cat, b, b, bird, tree dog, cat, c, c, bird, tree dog, cat, d, d, bird, tree
I have run splint on the code and it comes back clean so there are no obvious mistakes. What have I done wrong? Thanks,
> I am trying to insert a pattern of letters into a phrase. For example > the phrase is dog, cat, bird, tree. I want to have: > dog, cat, a, a, bird, tree > dog, cat, a, b, bird, tree > dog, cat, a, c, bird, tree > dog, cat, a, d, bird, tree > ... > dog, cat, d, c, bird, tree > dog, cat, d, d, bird, tree
> What I have now prints: > dog, cat, a, a, bird, tree > dog, cat, b, b, bird, tree > dog, cat, c, c, bird, tree > dog, cat, d, d, bird, tree
> I have run splint on the code and it comes back clean so there are no > obvious mistakes. What have I done wrong? > Thanks,
NUM_OF doesn't do what you want here. See question 6.21 on the comp.lang.c Frequently Asked Questions (FAQ) web page at <http://www.c-faq.com/>.
> if ((strncmp(&pattern[i],"!",1) == 0)&& (holdarea[i]< > (strlen(letters)-1))) {
I can't figure out what you're trying to accomplish -- it just makes no sense to me. What's the relationship between `i' (whose upper limit is derived from `words', sort of) and `pattern'? Why do you think the length of `pattern' depends on some attribute of `words'?
> while (done(words,letters,pattern)==0) { > changeup(words,letters,pattern); > printf("\n"); > }
> changeup(words,letters,pattern); //to get last phrase > printf("\n"); > return 0; > }
I haven't spent the time to examine your code in detail, because it's a warm summer afternoon at the start of a holiday weekend and my brain feels too lazy to try to figure out what you think these functions are supposed to do. At a guess, the `pattern' is supposed to emit one of `words' for each 'a' it contains, while each '!' asks for all of the `letters' to be emitted, one by one in the midst of the other words and letters. If so, you want sixteen lines of output from the example -- but nowhere do I see a loop that will execute sixteen times! The structure isn't right (not right for the intent I'm guessing at, anyhow). Maybe a clearer statement of what you're trying to do, complete with clear statements of what you think each function is supposed to do, would be helpful.
Now: If I swing my hammock *just* right, I can reach that piña colada without sloshing it ... Aahhh!
> > I am trying to insert a pattern of letters into a phrase. For example > > the phrase is dog, cat, bird, tree. I want to have: > > dog, cat, a, a, bird, tree > > dog, cat, a, b, bird, tree > > dog, cat, a, c, bird, tree > > dog, cat, a, d, bird, tree > > ... > > dog, cat, d, c, bird, tree > > dog, cat, d, d, bird, tree
> > What I have now prints: > > dog, cat, a, a, bird, tree > > dog, cat, b, b, bird, tree > > dog, cat, c, c, bird, tree > > dog, cat, d, d, bird, tree
> > I have run splint on the code and it comes back clean so there are no > > obvious mistakes. What have I done wrong? > > Thanks,
> I can't figure out what you're trying to accomplish -- it just > makes no sense to me. What's the relationship between `i' (whose > upper limit is derived from `words', sort of) and `pattern'? Why > do you think the length of `pattern' depends on some attribute of > `words'?
done is what tells me I have generated all of the phrases. changeup is supposed to change the letters, i.e. a a should become a b, then a c, then a d, etc. holdarea is an array of int that stores this information. When holdarea is 00 it prints aa, when it is 01 it prints ab, 02 is ac, etc.
> I haven't spent the time to examine your code in detail, > because it's a warm summer afternoon at the start of a holiday > weekend and my brain feels too lazy to try to figure out what > you think these functions are supposed to do.
Yeah it is a beautiful day here and I wish I was outside instead of here programming. That might be part of my problem :)
>done is what tells me I have generated all of the phrases. changeup >is supposed to change the letters, i.e. a a should become a b, then a >c, then a d, etc. holdarea is an array of int that stores this >information. When holdarea is 00 it prints aa, when it is 01 it prints >ab, 02 is ac, etc.
Your problem is in the changeup function. This expression is incrementing the wrong element of holdarea[]
> >done is what tells me I have generated all of the phrases. changeup > >is supposed to change the letters, i.e. a a should become a b, then a > >c, then a d, etc. holdarea is an array of int that stores this > >information. When holdarea is 00 it prints aa, when it is 01 it prints > >ab, 02 is ac, etc.
> Your problem is in the changeup function. > This expression is incrementing the wrong element of holdarea[]