Thread: File Stream I/O

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    29

    Unhappy 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

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    if (CountDown[A] = 0)

    Didn't you want this to be:

    if (CountDown[A] == 0)
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    29

    Exclamation

    Ok made that little change. Thanks

    Ive also added more comments to code to try and help you lot help me!



    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Question about file I/O from a newbie
    By henrik in forum C Programming
    Replies: 4
    Last Post: 11-13-2007, 12:48 AM
  4. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  5. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM