![]() |
|
#1
|
|||
|
|||
opening, reading adding writing to a text fileheey people,
I'm a newbie to c++ and got a problem with it. I need to open a text file need to know how big it is no problem their haha then read it. The problem is that i need to do an equation if the character read is smaller then hex 20 then this character--> ' is placed their and the character is written to the textfile. I found after some looking how to read a text file character by character but how can i do that equation that's my problem. I will put the code i think i'll use to read the text file CPP / C++ / C Code:
ps: I hope that this question is done according to rules if not let me know |
|||
|
#2
|
|||
|
|||
Re: opening, reading adding writing to a text fileQuote:
You could try something like: CPP / C++ / C Code:
Regards, Dave |
|
#3
|
|||
|
|||
Re: opening, reading adding writing to a text fileHmmm would that work
A character or multiple ones that is higher then 0x20 needs to be placed between quotes so if the first character is read and it's higher then 0x20 you first need to place a quote and then the character you read that's in the beginning at the end you also need to place a quote. I've modified my program a bit maybe now you'll better see what I want to do. CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: opening, reading adding writing to a text fileQuote:
I might organize it something like the following: Code:
Regards, Dave |
|
#5
|
|||
|
|||
Re: opening, reading adding writing to a text fileHeey dave,
thnx for the help but now he only puts a quote at the end of the file not the beginning really strange. my code is something like this now: CPP / C++ / C Code:
greetz |
|
#6
|
|||
|
|||
Re: opening, reading adding writing to a text fileHere you can see my output.
As you can see he only puts one quote not two and by those lines only at the end not the beginning don't know how to solve this problem "sigh" |
|
#7
|
|||
|
|||
Re: opening, reading adding writing to a text fileQuote:
Use the boolean operator '==' for comparison. The single '=' assigns the value true to quoteflag each time (and then executes whatever follows). Regards, Dave |
|
#8
|
|||
|
|||
Re: opening, reading adding writing to a text fileHeey dave,
thnx for that pointer can't believe I missed it sjeesh it works now so now I'll try writing it to another text file. I'll keep you posted on my progress hopefully this will work better and thnx again!!!! greetz Dadio22 |
|
#9
|
|||
|
|||
Re: opening, reading adding writing to a text fileHeey,
My program works almost could someone please look at my write method because I think their's a flaw in that because he writes the last character two times really weird. And does anybody know how I can search for a.txt file on the hardrive and then use it to do my program?? thanx in advance CPP / C++ / C Code:
|
|
#10
|
|||
|
|||
Re: opening, reading adding writing to a text fileQuote:
In your first post you had this: CPP / C++ / C Code:
In this one you have the following mistake, repeated in both functions. CPP / C++ / C Code:
The eof() flag and the fail() flag are set after you try to read past the end of the file. When you read the last character, the loop uses it, then it does another read. This fails, but you use the character anyhow. (The variable c still has the value from the last valid get().) You could go back to the original method (cin.get() before entering the loop, or you could do something like the following: CPP / C++ / C Code:
If you ever have file input inside a loop, you must test the state of the fstream object after trying to read and before trying to so something with whatever you were reading. Also, I really don't like the use of global variables in your latest program. It may seem like an expedient thing to do (and it may not be too hard to keep track of them in a small program), but it's generally not considered to be a good idea. (Makes debugging harder, and makes maintenance much more risky if/when the program is ever revised at some later time.) fstream objects can be passed by reference to the routines that need access. That's the proper way to have different functions that need access to a particular variable. Regards, Dave |
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 08:44 |
| Interface for opening and displaying text file | ladyscarlet99 | MS Visual C++ / MFC Forum | 0 | 29-Sep-2005 03:34 |
| Reading and Writing to a text file | raptorhawk | C++ Forum | 16 | 14-Apr-2005 14:09 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 11:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 12:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The