473,468 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

text editor

hi.
i have started on my first big project. i'm a newbee, no doubt... when
i compare the things i make with the things you people program. But
anyway, i'm attempting to re-make notepad (of windows XP). It wont be
as good, of course. But what i'll make is a tiny program that can store
blocks of text in one string and then save this string to disk. my
problem is that i'm not able to take input for my specifications. ex:
'i love programs' must be stored as 'i', '\0', 'l', 'o', 'v', 'e',
'\0', 'p', 'r', 'o', 'g', 'r', 'a', 'm', 's', '\r' (you may observe
that rather distinct '\r' after the whole string.... I want that as a
sign of saying....
"that's the end of the string" just like '\0' does in ordinary strings.
only difference here is that i want to store sentences in a string
rather than words.)

i have, of course, tried my hand at it.... and this is what i cooked-

char g;
for(int p = 0;p<1000;p++)
{
while((g = getche()) != '\r')
{ str[p] = g;}
if(g = '\r') { break; }
}

as you may have guessed, it DOESNT WORK!
please help me out.

Dec 8 '06 #1
14 1313
"MC felon" wrote:
i have started on my first big project. i'm a newbee, no doubt... when
i compare the things i make with the things you people program. But
anyway, i'm attempting to re-make notepad (of windows XP). It wont be
as good, of course. But what i'll make is a tiny program that can store
blocks of text in one string and then save this string to disk. my
problem is that i'm not able to take input for my specifications. ex:
'i love programs' must be stored as 'i', '\0', 'l', 'o', 'v', 'e',
'\0', 'p', 'r', 'o', 'g', 'r', 'a', 'm', 's', '\r' (you may observe
that rather distinct '\r' after the whole string.... I want that as a
sign of saying....
"that's the end of the string" just like '\0' does in ordinary strings.
only difference here is that i want to store sentences in a string
rather than words.)

i have, of course, tried my hand at it.... and this is what i cooked-

char g;
for(int p = 0;p<1000;p++)
{
while((g = getche()) != '\r')
{ str[p] = g;}
if(g = '\r') { break; }
Did you mean == instead of = ?
}

as you may have guessed, it DOESNT WORK!
please help me out.

Dec 8 '06 #2
osmium wrote:
"MC felon" wrote:
if(g = '\r') { break; }

Did you mean == instead of = ?
A good habit to get into to prevent this sort of thing (besides putting
your compiler on the highest warning level and using a lint-like
program to watch for this sort of thing) is to put constants first:

if( '\r' = g ) // Compile error! Should be ==

Cheers! --M

Dec 8 '06 #3

mlimber wrote:
osmium wrote:
"MC felon" wrote:
if(g = '\r') { break; }
Did you mean == instead of = ?

A good habit to get into to prevent this sort of thing (besides putting
your compiler on the highest warning level and using a lint-like
program to watch for this sort of thing) is to put constants first:

if( '\r' = g ) // Compile error! Should be ==

Cheers! --M
Thanks a lot!
so do you think it will work? and how do i assign '\r' to a char and
then attach it to the string (to signify the EOL (end of line)) ??

Dec 8 '06 #4
On 8 Dec 2006 08:12:48 -0800 in comp.lang.c++, "MC felon"
<pa******@gmail.comwrote,
>so do you think it will work? and how do i assign '\r' to a char and
then attach it to the string (to signify the EOL (end of line)) ??
I think you will have a happier time of it if you follow common c++
practices more closely. Use std::string for all your ordinary string
manipulation purposes, do not roll your own out of naked char arrays.
Use '\n' for EOL.
Read _Accelerated C++_ by Koenig & Moo, it is a good introduction to the
kind of code you are writing at this point.

Dec 8 '06 #5

MC felon wrote in message
<11**********************@n67g2000cwd.googlegroups .com>...
>
mlimber wrote:
>osmium wrote:
"MC felon" wrote:
if(g = '\r') { break; }

Did you mean == instead of = ?

A good habit to get into to prevent this sort of thing (besides putting
your compiler on the highest warning level and using a lint-like
program to watch for this sort of thing) is to put constants first:

if( '\r' = g ) // Compile error! Should be ==

Cheers! --M
>Thanks a lot!
so do you think it will work? and how do i assign '\r' to a char and
then attach it to the string (to signify the EOL (end of line)) ??
If you are using std::string:

myString.push_back( '\r' );

myString.at( 12 ) = '\r';

--
Bob R
POVrookie
Dec 8 '06 #6

If you are using std::string:

myString.push_back( '\r' );

myString.at( 12 ) = '\r';

--
Bob R
POVrookie
But what does member function 'push_back' mean?
i can see myString is an object, but where's my string 'str'?
what does the member function at(int somevar) do?
thanks for the new updates!

Dec 9 '06 #7

MC felon wrote in message ...
>
>If you are using std::string:
myString.push_back( '\r' );
myString.at( 12 ) = '\r';

But what does member function 'push_back' mean?
i can see myString is an object, but where's my string 'str'?
what does the member function at(int somevar) do?
thanks for the new updates!
Try this:

#include <iostream>
#include <ostream>
#include <string>

{ // main() or function
std::string str("Jello "):
std::cout<<str<<std::endl;
str.push_back( 'W' ); // add to string
std::cout<<str<<std::endl;
str.push_back( 'o' );
str.push_back( 'r' );
str.push_back( 'l' );
str.push_back( 'd' );
std::cout<<str<<std::endl;
str.at( 0 ) = 'H'; // change string
std::cout<<str<<std::endl;
str += "! Have a nice day.";
std::cout<<str<<std::endl;
return 0;
}

The '.at()' will throw an exception ('out_of_range') if you try an non-valid
index.

--
Bob R
POVrookie
Dec 9 '06 #8
Try this:

#include <iostream>
#include <ostream>
#include <string>

{ // main() or function
std::string str("Jello "):
std::cout<<str<<std::endl;
str.push_back( 'W' ); // add to string
std::cout<<str<<std::endl;
str.push_back( 'o' );
str.push_back( 'r' );
str.push_back( 'l' );
str.push_back( 'd' );
std::cout<<str<<std::endl;
str.at( 0 ) = 'H'; // change string
std::cout<<str<<std::endl;
str += "! Have a nice day.";
std::cout<<str<<std::endl;
return 0;
}

The '.at()' will throw an exception ('out_of_range') if you try an non-valid
index.

--
Bob R
POVrookie
Awesome! all these are contained in the Gnu, i suppose! thanks a bunch.
by the way, how do i learn more and more functions of the gnu? i'm
learning programming all by myself.

Dec 9 '06 #9

MC felon kirjoitti:
how do i learn more and more functions of the gnu? i'm
learning programming all by myself.
You should go and borrow a book of c++ from your local library or visit
http://www.cplusplus.com/doc/tutorial/ for online tutorial.

Dec 9 '06 #10

MC felon kirjoitti:
how do i learn more and more functions of the gnu? i'm
learning programming all by myself.
You should go and borrow a book of c++ from your local library or visit
http://www.cplusplus.com/doc/tutorial/ for online tutorial.

Dec 9 '06 #11
On Dec 9, 4:54 am, "MC felon" <paec....@gmail.comwrote:
all these [std functions] are contained in the Gnu, i suppose! thanks a bunch.
Yes, because GNU supports standard C++ (reasonably well, anyway). There
are also many other platforms on which that same code will work
identically -- that's the beauty of standardized language.
by the way, how do i learn more and more functions of the gnu? i'm
learning programming all by myself.
Get a good book or three (cf.
http://www.parashift.com/c++-faq-lit...html#faq-28.4).
I'd suggest you pick up _Accelerated C++_ by Koenig and Moo. IMHO, it
is the best book for learning to program C++ the right way from the
ground up.

Cheers! --M

Dec 9 '06 #12

mlimber wrote in message ...
>On Dec 9, 4:54 am, "MC felon" <paec....@gmail.comwrote:
>all these [std functions] are contained in the Gnu, i suppose! thanks a
bunch.
>
Yes, because GNU supports standard C++ (reasonably well, anyway). There
are also many other platforms on which that same code will work
identically -- that's the beauty of standardized language.
>by the way, how do i learn more and more functions of the gnu? i'm
learning programming all by myself.

Get a good book or three (cf.
http://www.parashift.com/c++-faq-lit...html#faq-28.4).
I'd suggest you pick up _Accelerated C++_ by Koenig and Moo. IMHO, it
is the best book for learning to program C++ the right way from the
ground up.

Cheers! --M
Add:
And while you are waiting for the postman to deliver that (a/some) book, try
this:

Get "Thinking in C++", 2nd ed. Volume 1&2 by Bruce Eckel
(available for free here. You can buy it in hardcopy too.):
http://www.mindview.net/Books/TICPP/...ngInCPP2e.html
[ Vol. 2 has a whole section on std C++ library. ]
Alf P. Steinbach's "Pointers" document:
http://home.no.net/dubjai/win32cpptu...ters/ch_01.pdf

--
Bob R
POVrookie
Dec 9 '06 #13

THANKS! i always wanted a book/documentary on pointers! and thanks for
all!

Dec 10 '06 #14
MC felon wrote:
Awesome! all these are contained in the Gnu, i suppose! thanks a bunch.
by the way, how do i learn more and more functions of the gnu? i'm
learning programming all by myself.
None of this has anything to do with GNU.
Dec 10 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Ed Suominen | last post by:
I'm thinking of implementing a real-time collaborative text editor in Python using Twisted. An initial plan is to use a Twisted PB server daemon that accepts user:password:file connections from...
27
by: Eric | last post by:
Assume that disk space is not an issue (the files will be small < 5k in general for the purpose of storing preferences) Assume that transportation to another OS may never occur. Are there...
1
by: IkBenHet | last post by:
Hello, I found this script to create a simple rich text form (http://programmabilities.com/xml/index.php?id=17): <html> <head> <title>Rich Text Editor</title> </head> <body>
14
by: SD | last post by:
I am thinking about writing a text editor in C for unix sometime soon. I am just doing this to learn more about C. I want to write something like ed.c, a simple line editor. What types of data...
2
by: Rudy Ray Moore | last post by:
Hi guys, I just upgraded to "Visual Studio .net 2003 7.1 c++" from VS6. Some things I like (proper for loop variable scoping, for example), but some other things are troubling me. One...
4
by: pbreah | last post by:
I'm doing a Rich Text Editor (WYSIWYG) in javascript for a game for kids. I'm doing a special case in with every keystroke from A-Z creates a background and foreground color for that letter, witch...
0
by: karen987 | last post by:
Could someone please tell me what code to add here? I have a weblog, with daily news which readers can add comments to, which are stored in a database. The form to add the comments is on an ASP page,...
36
by: karen987 | last post by:
My newsweblog has ASP pages with news articles and a commenting system. The comments are posted, and to read them the reader clicks on the headline of the comment, and it opens up in a pop up window....
1
by: Victor | last post by:
Hi guys I have a small question abou the vs2005's text editor. in my text editor, any space or tabs become little dot. i forget what shortcut i pressed.It looks not right to me at all. Can anyone...
3
by: danesh1354 | last post by:
Hi All, First I need to construct a text editor by python programming and add this code to a biger code that has been written before, and i would like that by my code for this editor have a...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.