Teen Programmers Unite  
 

 

Return to forum top

files and arrays in c++

Posted by muffdust [send private reply] at May 24, 2001, 01:59:45 PM

here is (one of ) my problem:

i have a function that reads in a file to memory, once the file is read, the file is emptied.

I can read in from the file (ish) but i get the file contents 20 times (my array has a size of 20)
then how do i empty the file?

here is my code id it helps:

void job::readFromFile()
{

const int arraysize = 20;
int i ;

ifstream inputFile( "jobs.dat", ios::in);
string test[arraysize];

for ( i = 0; i < arraysize; i ++)

{
inputFile >> test[0] >> test[arraysize];
cout << test[0] << test[arraysize];
}

}


jobs.day is just a list of jobs:

[1]_Broken_Floppy_Drive._GG201_Fred Bloggs._25/1/2001_:_Pending

[2]_Printer_malfunction._GG107:_John_Smith._24/1/2001_:_Resolved

[3]_Workstation_Doesn't_boot._JG252A:_Peter_Piper._23/1/01_:_Pending



Posted by Psion [send private reply] at May 24, 2001, 09:34:01 PM

Please try to explain what you want to be able to do more clearly. It didn't come across to me.

Posted by gian [send private reply] at May 25, 2001, 05:04:32 PM

I don't see why people instisting on using C++ for things where C would suffice nicely. You realise that at my school they stopped teaching C! They only teach BASIC and C++, a common move from what I've heard. In C, you could empty the file with.

FILE *fp = fopen("somefile.txt", "w");
fclose(fp);

Posted by Psion [send private reply] at May 25, 2001, 06:18:37 PM

gi-gi, it's just as easy in C++. The code used between iostreams and stdio stuff is entirely isomorphic.

Posted by gian [send private reply] at May 26, 2001, 04:53:28 PM

But do youi not agree with me that C is being phased out in favour of a language that is only superior in some very minor ways?

Posted by taubz [send private reply] at June 03, 2001, 04:51:45 PM

C++ is technically more advanced, but far less important to understanding programming... And, you're right gian. I'm seeing it being phased out too.

- taubz

Posted by lordaerom [send private reply] at June 03, 2001, 09:50:50 PM

Feh, neither should be used for teaching programming. Scheme or SmallTalk, now that'd be fun!

Posted by RedX [send private reply] at June 05, 2001, 12:51:32 PM

No, they should teach Assembly. By the time they learned their first "Hello World"-program, they'll be able to type with 10 fingers (blind).

RedX

Posted by Setherd123 [send private reply] at June 05, 2001, 02:21:30 PM

I type with 9 fingers, and I'd find it very difficult to type with 10. I don't use me left thumb! While I'm typing this I have the urge to plant my left thumb on the space bar but me hands won't allow it!

Posted by gian [send private reply] at June 05, 2001, 04:26:03 PM

Are your hands locked in one position seth? Used to making rapid motions?

Posted by RedX [send private reply] at June 06, 2001, 01:13:34 PM

At school we have the worst kind of keyboard I could think of. Imagine the spacebar split in two and one part used as backspace. Just terrible.
I'm used to an old Dos-kind-of keyboard, without those
windows-keys-<very bad word> So I spend more time retyping the last letter of my words than actually typing something (relative) usefull.
And I'm pretty sure this is actually designed as some sort of evil experiment.
<insert some sort of conspiracy theory>

RedX

Posted by Setherd123 [send private reply] at June 08, 2001, 03:05:03 AM

gian:

Masturbation is bad.

Posted by gian [send private reply] at June 08, 2001, 08:30:35 PM

Seth: That makes you a very bad boy!

Posted by CHollman82 [send private reply] at June 14, 2001, 09:53:09 PM

interacial homoeroticism aside, I agree that C is being fazed out, but who cares. C++ can do exactly the same things that C can do plus much more, granted, there is increased overhead, but again, who cares. Im running on 256mb of ram, quite typical right, Id like to see increased overhead overflow my ram.

Posted by sphinX [send private reply] at June 15, 2001, 06:28:44 AM

True, I have yet to run out of RAM (also running 256Mb) in even Windows, but I tend to prefer C over C++, I just love the feel of scrolling through pages of C code, I find it more "appealing" (what was that about homoeroticism? :-)) than C++......just my opinion.

Posted by gian [send private reply] at June 15, 2001, 05:19:08 PM

C++ just seems a little to "out of the box" for me... it's like they will have a microsoft C++ wizard next. You don't do anything, you just type your name and press "next".

Posted by lordaerom [send private reply] at June 15, 2001, 08:33:26 PM

I don't know whether to laugh or cry!

Posted by sphinX [send private reply] at June 15, 2001, 10:01:32 PM

wizard question #2 (after divesting your name): Select your genre codebase: a) First Person Shooter b) Racing game c) Massive Online Role Playing Game --- you selected First Person Shooter!!!! Please enter the name of your new game:


Thank you for using the Microsoft C++ Wizard!! Your precompiled game will be emailed to you shortly and then you can begin to market it. Don't forget the 90% royalties to Microsoft.

Posted by CHollman82 [send private reply] at June 16, 2001, 07:04:24 PM

I think API's are bad enough. If it were up to me everyone would hard code everything in pure ASM.

Posted by lordaerom [send private reply] at June 16, 2001, 07:05:10 PM

That is sarcasm!!!

Posted by gian [send private reply] at June 18, 2001, 09:45:44 PM

Mr. Hollman: No.

Posted by CHollman82 [send private reply] at June 19, 2001, 10:42:41 PM

The genius of your post lies in its simplicity...

Posted by gian [send private reply] at June 19, 2001, 10:54:05 PM

The genius in your post, or lack of, was the absolute stupidity of that statement! Would you prefer to directly interface with video cards yourself! How about writing your own windowing system while you're at it!

Posted by infryq [send private reply] at June 21, 2001, 12:45:56 PM

write your own windowing system? why not? :)
hey, if you've got the time...

Posted by CHollman82 [send private reply] at June 24, 2001, 02:23:23 PM

like lordaerom said "that is sarcasm [dumbass]"

Posted by gian [send private reply] at June 26, 2001, 11:50:42 PM

Thank god he's going away, so I dont have to waste processor cycles on writing a cynical reply to his remark.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.