![]() |
|
#1
|
|||
|
|||
Weird printing problemsI am writing a lexical analyser. Almost done except for one minor problem,
one my my functions can't count words and I don't know why ? I got it to work twice then it crapped out. Here is the code. CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: wierd printing problemsI don't see where print_out() gets called. I see it in your maim() function but it seems to be commented out and incomplete. I don't see a main() function either. More than likely, your problem lies in the fact that you expect the stats[] in word_stats() to be the same array as the one passed into print_out(). This is not the case because it is a local variable for the word_stats() function. Instead, maybe you should take it in as a parameter like you did in the print_out() function.
|
|
#3
|
|||
|
|||
Re: wierd printing problemsQuote:
maim is main() . |
|
#4
|
||||
|
||||
Re: wierd printing problemsI think this is what you're trying to accomplish:
CPP / C++ / C Code:
The stats array in your word_stats function is only local to that function. When the function returns, the array no longer exists, so the function isn't really doing anything. You need to give it the array as a parameter (or use a global variable). I also got rid of the big switch statement, and changed the for loop to a while loop (that's just a matter of preference, the way you had it was fine). __________________
www.blake-foster.com |
|
#5
|
|||
|
|||
Re: wierd printing problemsQuote:
That's a COOL solution. Why didn't I think of that. |
|
#6
|
|||
|
|||
Re: wierd printing problemsQuote:
One final problem It's a biggy. It doesn't tally the words . Here is the code. CPP / C++ / C Code:
I put the parsing loop (while loop) word_stats in the main(), and the affect is the same. I tried passing parameters to read out, it still didn't help... |
|
#7
|
||||
|
||||
Re: wierd printing problemsYou're no longer including a space in the delimiters for strtok. I've fixed the problem below (and I added some other punctuation marks). It would be best to put the delimiters in a variable, so that if you ever change them, you only need to change them in one place.
I don't see letter_stats or same_word_count defined in your code, so I commented them out. I've made a few other changes too (call them suggestions): I'm assuming that stats is a global variable that got left out by mistake when you posted your code. I added it at the top. I added a for loop to your read_out function to replace all the couts. I changed all occurrences of "sentance" to the correct spelling. I changed the length of your sentence variable to 50, so that it matches the buffer size you pass to cin.getline. CPP / C++ / C Code:
__________________
www.blake-foster.com |
|
#8
|
|||
|
|||
Re: wierd printing problemsword_stats still does not show the total.
|
|
#9
|
||||
|
||||
Re: wierd printing problemsCould you post ALL of your code? And whatever output it's giving you? When I run the code I posted above, it works exactly as it's supposed to.
__________________
www.blake-foster.com |
|
#10
|
|||
|
|||
Re: wierd printing problemsQuote:
CPP / C++ / C Code:
I tried global and local. One time stats gave me garbage when I made it local. Then I initialised it ,and it gaves me 0's args... |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| IE 7 Problems | colliegirl | Computer Software Forum - Windows | 6 | 05-Jun-2008 08:10 |
| Problems while burning CD's | netnut | Computer Software Forum - Windows | 16 | 17-Jan-2008 23:45 |
| Printing problems--->ARG! | toddm123 | .NET Forum | 0 | 31-Mar-2005 12:51 |
| Chaintech Geforce 5600 FX problems | bartster74 | Computer Hardware Forum | 8 | 04-May-2004 13:16 |
| Serious Problems: Exabyte Products and Service | pkazmercyk@comc | Computer Hardware Forum | 2 | 05-Feb-2004 07:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The