-
File Stream I/O
HI,
Ive got a txt file with 120 lines in it, basically all i want to do is read through each line in it (looping around) and once in that line position, check to see if it contains an "R", if it does then i want to do something!
Ive had a go at doing this, as you can see from the code below. But got an error, also shown below! Please try and help in any way you can!
Code:
//Automatic Reset
int CountDown[120];
int A;
char Buf[1];
long Dist;
int NumRead;
char Blank[2] = " ";
while (TRUE)
{
Sleep(100);
for ( A = 1; (A >= 1) && (A <= 120); A++)
{
Dist=(6 + ((A - 1) * 9));
pnHandle = fopen(gtRESET_FILE, "r+");
pnSize = fseek(pnHandle, Dist, SEEK_SET);
NumRead = fread(Buf, 1, 1, pnHandle);
if (Buf == "R")
{
CountDown[A] = 300;
//Do Block Here, Somehow??!
iPutEvent(A, GCEV_BLOCKED);
fwrite(Blank, 1, 1, pnHandle);
}
CountDown[A]--;
if (CountDown[A] = 0)
{
//Do UnBlock Here, Somehow??!
iPutEvent(A, GCEV_UNBLOCKED);
}
}
}
Error
-------------
Compiling...
EventHandler.cpp
C:\SMS\sms_c_V4\EventHandler.cpp(1121) : warning C4101: 'itemp' : unreferenced local variable
C:\SMS\sms_c_V4\EventHandler.cpp(1637) : error C2440: '=' : cannot convert from 'int' to 'struct _iobuf *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
EventHandler.obj - 1 error(s), 1 warning(s)
----------------
Thanks for any help whatsoever,
P :(
-
if (CountDown[A] = 0)
Didn't you want this to be:
if (CountDown[A] == 0)
-
Ok made that little change. Thanks
Ive also added more comments to code to try and help you lot help me! :p
Code:
//Automatic Reset
//Array to countdown the 120 lines
int CountDown[120];
int A;
//Array to store read in Char
char Buf[1];
long Dist;
int NumRead;
//Char array containing the blank space
char Blank[2] = " ";
while (TRUE)
{
Sleep(100);
for ( A = 1; (A >= 1) && (A <= 120); A++)
{
//Number of bytes from the start of file to begin reading
Dist = (6 + ((A - 1) * 9));
//Open the file with read & write access
pnHandle = fopen(gtRESET_FILE, "r+");
//ERROR POINTS HERE!!!!!
//Move file pointer to correct position
pnSize = fseek(pnHandle, Dist, SEEK_SET);
//Read one byte from position and store in Buf
NumRead = fread(Buf, 1, 1, pnHandle);
//Check to see if that line needs reseting
if (Buf == "R")
{
//Start countdown
CountDown[A] = 300;
//Block line
iPutEvent(A, GCEV_BLOCKED);
//Remove the "R" from the ResetFile.txt file
fwrite(Blank, 1, 1, pnHandle);
}
//Decrement the value at current position in the array
CountDown[A]--;
//If the value at the current position in the array is zero unblock line
if (CountDown[A] == 0)
{
//UnBlock line
iPutEvent(A, GCEV_UNBLOCKED);
}
}
}
ERROR
--------------------Configuration: sms_c - Win32 Debug--------------------
Compiling...
EventHandler.cpp
C:\SMS\sms_c_V4\EventHandler.cpp(1121) : warning C4101: 'itemp' : unreferenced local variable
C:\SMS\sms_c_V4\EventHandler.cpp(1650) : error C2440: '=' : cannot convert from 'int' to 'struct _iobuf *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
EventHandler.obj - 1 error(s), 1 warning(s)
Any more help anyone? :(
Thanks :)