Closed Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Help to create NotePad in c++

  1. #1
    mindblaster's Avatar
    mindblaster is offline Newbie
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Cool Help to create NotePad in c++

    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.

    Join SuperDiscountShop.com at Facebook.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: Help to create NotePad in c++

    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 /

  4. #3
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Help to create NotePad in c++

    Yeah, conio kind of doesn't work anywhere but Windows, at least use ncurses... that's still updated!
    Wow I changed my sig!

  5. #4
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: Help to create NotePad in c++

    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<<" ";
    }
    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:
    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 /

  6. #5
    mindblaster's Avatar
    mindblaster is offline Newbie
    Join Date
    Jul 2009
    Posts
    17
    Rep Power
    0

    Wink Re: Help to create NotePad in c++

    Quote Originally Posted by dargueta View Post
    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<<" ";
    }
    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:
    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;
    }
    its run on windows

  7. #6
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: Help to create NotePad in c++

    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 /

  8. #7
    outsid3r's Avatar
    outsid3r is offline Programming God
    Join Date
    Jul 2008
    Posts
    621
    Rep Power
    19

    Re: Help to create NotePad in c++

    He is probably using turbo C++...

  9. #8
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: Help to create NotePad in c++

    I don't know why people still use that. There are plenty of more modern--and free--things out there.
    sudo rm -rf /

  10. #9
    outsid3r's Avatar
    outsid3r is offline Programming God
    Join Date
    Jul 2008
    Posts
    621
    Rep Power
    19

    Re: Help to create NotePad in c++

    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!

  11. #10
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: Help to create NotePad in c++

    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 /

Closed Thread
Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 07-23-2010, 03:41 AM
  2. compile from notepad++
    By rivci in forum Java Help
    Replies: 16
    Last Post: 05-11-2010, 05:05 PM
  3. Manipulate Notepad
    By EdSquareCat in forum Java Help
    Replies: 5
    Last Post: 11-13-2009, 02:25 PM
  4. how to use Notepad++
    By Shanpav in forum C and C++
    Replies: 10
    Last Post: 10-12-2009, 02:37 PM
  5. Notepad++
    By xXHalfSliceXx in forum C and C++
    Replies: 15
    Last Post: 01-29-2007, 09:17 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts