![]() |
| ||
| Line count not working.... hey, This might be naive, but how come this bit of code isn't working??? int lc=0; Have looked through the internet, and this code seems to be fine, so what is it that makes it not work?? the output is always 0, no matter what file I try to open. |
| ||
| Re: Line count not working.... You should check that the file actually opened. read.open(filename_user.c_str(), ios::in); Are you sure the data file is in the place where your program is looking for it? |
| ||
| Re: Line count not working.... Actually, it does check whether the file is open and it does also show the contents of the file...The only thing that doesn't work is the line count I made. But I see what you mean: Below is the whole code:
In the code, it checks for the existence of the file before opening...and it does output the file contents...Only thing not working is the line count. Is the method correct? |
| ||
| Re: Line count not working.... Why don't you just create a simple linecount program to see where you're going wrong? |
| ||
| Re: Line count not working.... 1 Attachment(s) Quote:
There are a few other things wrong with your program, but I guess this isn't all of it? Anyway, here's a small example for linecounting. #include <iostream> Just out of curiosity: You do know that void main() doesn't exist right? I'm referring to your signature... Also: Using goto is considered bad coding-practice. 99.9% of the cases (including yours) the better answer would be to use a loop. See attachment ps. You could also have a look at indenting code |
| ||
| Re: Line count not working.... Quote:
|
| |||
| Re: Line count not working.... Quote:
Quote:
Quote:
And you're correct, This is just a part of a bigger program. I'll try your code out and will try and modify my own... Thanks for all the replies... [EDIT]Thanks for your code and advice, 'niek_e', it helped such a lot! The code's finally working!! |
| ||
| Re: Line count not working.... Why even bother reading the signature?(although you got to admit, some are pretty funny) |
| ||
| Re: Line count not working.... Quote:
|
| ||
| Re: Line count not working.... Quote:
Quote:
void main()isn't standard C++, so every time I encouter it, I mention it to the poster. That way, when/if the poster gets a job in the programming-field, he/she won't get laughed out of the building by using void main(). What difference does it make if I see it in the post or in the signature? |
| All times are GMT -4. The time now is 9:38 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC