I have all this code for my project which is to copy a file to another file using windows coding in C ++ i have to repeat the the code 5 times using diffrent buffers everytime which the numbers are 1, 5, 10, 100, 1000 i know i have to put in a FOR loop for this to work but i dont know how to set the pointer back to the beginning of the text file.. i have the code for everything else except for that part here is the code if anyone can help it would be appreciated...

#include <windows.h>
#include <stdio.h>
#include <time.h>
#define BUFFER_LEN 10

//***********************************************************************
//    Program reads information from the file name "constitution.txt" then writes
//	it to the file named "NewVersionConstitution.txt"
//************************************************************************

void main (void)
{

//***********************************************************************
//	Local Variables
//************************************************************************

	char buffer[BUFFER_LEN+1];

//***********************************************************************
//	CreateFile parameters
//***********************************************************************

	DWORD dwShareMode = 0;									// share mode
	LPSECURITY_ATTRIBUTES lpFileSecurityAttributes = NULL;  // ptr to sec att
	HANDLE hTemplateFile = NULL;							// handle to file

//***********************************************************************
//	Read File Parameters
//************************************************************************

	HANDLE		  SourceFile;							// Source File
	DWORD		  NumberofBytesRead;					// Number of Bytes Read
	LPOVERLAPPED  lpoverlapped = NULL;					// not used here

//***********************************************************************
//	Write File Parameters
//************************************************************************

	HANDLE		  SinkFile;			// output File
	DWORD		  NumberofBytesWritten;	// Number of Bytes Written

//***********************************************************************
//	Open the source file
//************************************************************************

	SourceFile = CreateFile
		(
		"Data.txt",
		GENERIC_READ,
		dwShareMode,
		lpFileSecurityAttributes,
		OPEN_ALWAYS,
		FILE_ATTRIBUTE_READONLY,
		hTemplateFile
		);
	if(SourceFile == INVALID_HANDLE_VALUE)
	{
		printf("Source File ---- File Open Operation Failed \n");
		ExitProcess(1);
	}
//***********************************************************************
//	Open the Output file
//************************************************************************

	
	SinkFile = CreateFile
		(
		"NewData.txt",
		GENERIC_WRITE,
		dwShareMode,
		lpFileSecurityAttributes,
		CREATE_ALWAYS,
		FILE_ATTRIBUTE_NORMAL,
		hTemplateFile
		);
	if(SinkFile == INVALID_HANDLE_VALUE)
	{
		printf("Output File ---- File Open Operation Failed \n");
		ExitProcess(1);
	}

//***********************************************************************
//	Main loop to copy the file
//********************************************************************************/
    clock_t start, finish;
	
	double duration;
	start = clock();
	
	
	while (ReadFile(SourceFile,buffer,BUFFER_LEN,&NumberofBytesRead, lpoverlapped) 
		    && NumberofBytesRead >0)
	{
		WriteFile(SinkFile,buffer,NumberofBytesRead,&NumberofBytesWritten, lpoverlapped);
	}
	finish = clock();
	printf("\n******elapsed time for quicksort*********");
	duration = (double)(finish - start)/ CLOCKS_PER_SEC;
	printf("\n clock ticks = %19.05f\n", (double)(finish - start));
	printf("\n seconds = %19.05f\n", duration);
//***********************************************************************
//	Terminating , close the files
//************************************************************************

	printf("****  Output File successfully Created  **** \n\n\n");
	char ch;
	printf("****  Press Any Key To Terminate the program **** \n\n\n");
	ch = getchar();
	CloseHandle(SourceFile);
	CloseHandle(SinkFile);
	ExitProcess(0);
}

i dont know how to set the pointer back to the beginning of the text file..

Use SetFilePointer to move the file pointer of an open file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.