473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

help with file i/o

hey i am trying to write a program that saves logs and i have basically 3 columns session time,total time and comments in that order

what i want to do is read in the total time on the last line, and store it in 3 variables hr, min, sec then add the current session time to get teh new total time .

i was trying to use StreamReader and the compiler is visual c++ 2003

a sample of the first line in the log file is below:

00 : 00 : 04 --- 00 : 00 : 04 --- Comments...
any help will be much appreciated thanks

oh and sorry if this is in the wrong forum im new here lol
Oct 8 '07 #1
11 1397
Shashi Sadasivan
1,435 Expert 1GB
hi,

this would most probably be shifted to the C++ forums.

But anyhows...
Is your issue that you do not know how to start coding your pseudo code?
or are you facing issues within the code execution?

cheers
Oct 8 '07 #2
well i guess i am having problems with code... this is my first real windows forms project... anyways the problem is that i need something that will work like fscanf in C so that i can read in the integers or even the numbers as a string up to the whitespace which i can then convert to an int.

am i making myself clear?

i was using the streamreader class but Read() only reads a single char and ReadLine() isnt applicable here... ReadBlock() seems to be the better choice but the complicated data types makes it too confusing and hard to implement.

i was even thinkin abt reading each number as a letter and convert to in then multiply by 10 and add the number after it so for e.g 48 =(4x10)+8 but that seems like too long a roundabout way to do it.
Oct 8 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
have you been able to read the file?

C++ should have an equivalent of what .Net has "Split"
So read each line in your file, and then once you have the last line.. use the split on that line, splitting on "---" so that you can get all 3 fields in seperate strings.

cheers
Oct 8 '07 #4
ok thanks for the help but i am still having some probs

String* tempLine;
String *splitLines[] = NULL;
//String *time[] =NULL;

char splitter[] = {" --- "};
//Char splitter2[] = " : ";


splitLines = tempLine->Split(splitter);
the compiler is telling me that it cannot convert from char[6] to __wchar_gc
even if i put the delimiter in directly
Oct 8 '07 #5
no help from anyone???
Oct 10 '07 #6
Plater
7,872 Expert 4TB
Not many people use c++ for .NET applications. So most of us are probably scratching our head. VB.NET and C# differ mostly by simple syntax convention.
C++ with .NET seems to be waaay different.

I have no idea what a __wchar_gc is.

But if you manage to get a string[] of the values, There should be like Int.Parse() and Double.Parse() and various other datatypes all have the .Parse() function which will take a string and attempt to make a datatype from it.

i.e. int myint =int.Parse("123");//makes myint=123
Oct 10 '07 #7
hmmm thanks for the reply...yeh i realise ppl mostly use c# and VB the prob is that i dont know either lol... anyways i'll try your advice and see if it works.
Oct 10 '07 #8
ok that didnt work.... i tried rewriting the function and this is what i have (well the part that deals with the reading from file....


Expand|Select|Wrap|Line Numbers
  1. FileStream *fst = new FileStream(sfd->FileName,FileMode::OpenOrCreate);
  2.              FileInfo *fptr = new FileInfo(sfd->FileName);
  3.              BinaryReader *freader = new BinaryReader(fst);
  4.              StreamWriter *fwriter = new StreamWriter(fst);
  5.              int oldHr ,oldMin, oldSec, lineCount=0;
  6.  
  7.              if (File::Exists(sfd->FileName)){
  8.                  while (freader->ReadString() != NULL){
  9.                     lineCount++;
  10.                  }
  11.  
  12.                 freader->BaseStream->Position= 0;
  13.                 for (int i=0; i< (lineCount -1);i++)
  14.                     freader->ReadString();
  15.                 for (int j=0; j<17; j++)
  16.                     freader->Read();
  17.  
  18.                 oldHr = freader->ReadInt32();
  19.                 freader->ReadChars(3);
  20.                 oldMin = freader->ReadInt32();
  21.                 freader ->ReadChars(3);
  22.                 oldSec = freader->ReadInt32();
  23.  
  24.  
  25.                     oldSec += sec;
  26.                     if (oldSec >= 60){
  27.                         oldMin++;
  28.                         oldSec -=60;
  29.                     }
  30.                     oldMin += min;
  31.                     if (oldMin >=60){
  32.                         oldHr++;
  33.                         oldMin -=60;
  34.                     }
  35.                     oldHr += hr;
  36.  
  37.                     fwriter = fptr->AppendText();  // if it exists append to file
  38.              }
  39.  
  40.  
Oct 11 '07 #9
Shashi Sadasivan
1,435 Expert 1GB
is it giving any errors?
I would presume that readInt32 would be causing your problem.
As the file is a text file, and you are reading binary data from it for int32 ie(4bytes = 4 characters)
I think you should read it as characters and then convert it to integers.

cheers
Oct 12 '07 #10
it compiles fine... but now that i redid it it is giving the error 'unable to read beyond end of stream' when i try to save the file (when it reads the file)

i think im getting that error because now with binary stream im not sure how to get to the last line

before i was using StreamReader but i couldnt get the data i needed from the line.
Oct 12 '07 #11
Shashi Sadasivan
1,435 Expert 1GB
Compilation wouldnt be a problem.
it will be at runtime because you are trying to read more data than what the file actually has.
lets take this example
00 : 00 : 00
this takes 12 bytes
if we take the concept of reading int32 then 3 chars then int32 then 3 chars and then int32,
then that means u are reading 4 + 3 + 4 + 3 + 4 = 18bytes.
no wonder it runs out of the file.

So read it as chars, and convert the chars to int.

cheers
Oct 12 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
2
by: fabien | last post by:
Hi, I am writing a POV-RAY editor with Python using either QT or GTK as GUI 'wrapper'. ( I am still trying both ) * * * * PYGTK * * * * I have downloaded PygtkScintilla-1.99.5. There is a...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
4
by: dixie | last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I have just installed HTML Help in an application. I told it in the Project Properties the path to the help file. I then...
1
by: Tim Marshall | last post by:
I'm putting together my first help file (using Easy Help, http://www.easyhelp.com/). So far, so good. I'm able to use the Help File and Help Context ID to have things from my help file pop up...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
22
by: KitKat | last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7, and Cam 8. Well it does that but it also needs to change the file name to the same folder where the file is being...
3
by: lord.zoltar | last post by:
I've managed to get a nice little chm help system written. Now I need to display it! I added a HelpProvider to my MDIParent form and set the namespace of the HelpProvider to be the help file. So...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
6
by: priyajohal | last post by:
#include<fstream.h> #include<process.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include<dos.h> #include<ctype.h> #include<stdio.h> void setup() void help();
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.