this is my program to create notepad in c++. i have some difficulties to count line number to remove character. I have done removing charecter in given number.
help me...
Code:#include<conio.h> #include<stdio.h> #include<string.h> #include<iostream.h> class NotePad { private: int x; int y; int key; int total_chars; int total_words; int total_sentance; int line[100]; public: void clipboard() { x=1,y=1,total_words=0,total_chars=0; int line_index=0; while(key!=27) { gotoxy(1,50);cout<<"Col: "<<x<<" "; gotoxy(11,50);cout<<"Rows: "<<y; gotoxy(21,50);cout<<"Total Chars: "<<total_chars; gotoxy(40,50);cout<<"Total Words: "<<total_words; total_chars++; gotoxy(x,y); key=getch(); gotoxy(x,y);printf("%c",key); if(key==13) { y++; line[y]=x; x=1; } else if(key==32) { total_words++; } else if(key==8) { x=line[y]-1; gotoxy(x,y);cout<<" "; } else { x++; } } } }; void main(void) { clrscr(); NotePad np; np.clipboard(); getch(); }
Last edited by mindblaster; 08-23-2009 at 01:35 AM.
Care to be more specific on what exactly the problem is? Your code looks ok, though I'm wondering why you're using conio.h. It's pretty old and definitely not standard.
sudo rm -rf /
Yeah, conio kind of doesn't work anywhere but Windows, at least use ncurses... that's still updated!
Wow I changed my sig!
This is bad. No, no, no, no. Not portable, not clear at all. This might run on Linux but will fail on Windows, or vice-versa.Code:if(key==13) { y++; line[y]=x; x=1; } else if(key==32) { total_words++; } else if(key==8) { x=line[y]-1; gotoxy(x,y);cout<<" "; }
Code:switch(key) { case '\n': y++; line[y]=x; x=1; break; case ' ': total_words++; break; case '\t': x=line[y]-1; gotoxy(x,y); cout<<" "; break; }
sudo rm -rf /
Operative word being might. You can't just rely on the character codes being correct like that. At the very least swap '\t' for 8 and so on.
sudo rm -rf /
He is probably using turbo C++...
I don't know why people still use that. There are plenty of more modern--and free--things out there.
sudo rm -rf /
I agree, probably it's because of his school, there are plenty of schools that still use turbo C to teach, and there is one thing even more stupid, some schools even use pascal to teach programming!
It makes me cry inside...
By the way, standard C++ headers don't have .h extensions. Use iostream, not iostream.h - the latter is older and not really supported anymore except for backwards compatibility. Same goes for the old standard C headers. Just prefix a 'c' and drop the .h extension. Your includes should look like:
Code:#include <iostream> #include <cstdio> //stdio.h #include <cstring> //string.h #include <conio.h> //note - not a standard C header, so leave it alone.
sudo rm -rf /
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks