write a function called readAny having the following declaration:
void readAny(fstream &iofile, char buffer[], int size, int start, int index);
with five parameters, iofile is the fstream variable for reading the file. Assume that the file has already been opened. buffer is the character array for returning the bytes that will be read in by the function. size specifies how many bytes to read in. start will have one of three constants 1, 2, or 3. 1 means from the beginning, 2 means from the current position, and 3 means from the end. index specifies the index location to read from relative to what is specified in start. for example, readAny(iofile, buffer[], 20, 3, 45) will read in 20 bytes starting from location 45 from the end into the character array buffer
I have written function which exactly solves your question. I have included comments to each line to understand better. If you are satisfied with the answer please like. If you have any doubts please comment.
CODE:
void readAny(fstream &iofile, char buffer[], int size, int
start, int index)
{
//start = 1 represents read file from beginning
if(start==1) iofile.seekg(index, ios::beg);
//start = 2 represents read file from current position
else if(start==2) iofile.seekg(index, ios::cur);
//start = 3 represents read file from the end
else if(start==3) iofile.seekg(index, ios::end);
//read size length from the file into buffer
iofile.read(buffer, size);
//ending the buffer with a null terminating character
buffer[size] = 0;
}
write a function called readAny having the following declaration: void readAny(fstream &iofile, char buffer[], int size, int start, int index); with five parameters, iofile is the fstream variable...
MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file: 6 a e m r s t 10 ate eat mate meet rate seat stream tame team tear Here are some suggestions for constants, array declarations, and helper functions #include <iostream> #include <fstream> #include...
Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and returns the index of the "last occurrence" of the largest element in the array. Include another function to print the array. Also, write a program to test your function. [HINTS) Create an array of size 15 in the main function and initialize it with the values shown in the below sample output. Pass the array and its size to function lastLargestindex; function lastLargestindex returns...
C PROGRAMMING ONLY 22 2 points Write a function for the following specs: • type: int • parameter: character array • Behavior: o Open the file using the parameter for the file name in read mode. o Return O if the file opened successfully, 1 if unable to open the file. В І о A- A Ex x, EE 12 23 2 points Write a function for the following specs: type: void • parameters: FILE", int[], int size Behavior: o...
The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() { char board[SIZE]; int player, choice, win, count; char mark; count = 0; // number of boxes marked till now initBoard(board); // start the game player = 1; // default player mark = 'X'; // default mark do { displayBoard(board); cout << "Player " << player << "(" << mark...
I. Which Statements modify a shared critical variable to indicate that another slot in the buffer is available? J. Describe an application of a monitor- controlled circular buffer within a Operating System. 3 char circularBuffernew char BUFFER SIZE, // buffe:r 4 int writerPosition-0; // next slot to write to 5 int readerPosition0; // next slot to read from 6 int occupiedSTots-0 / number of slots with data // condition variable // condition variable 7Condition hasData; 8 Condition hasSpace; 10 /...
You are to write three functions for this lab: mean, remove, display. Download the main.cpp file provided to get started. Read the comments in the main function to determine exactly what the main function should do. //include any standard libraries needed // - Passes in an array along with the size of the array. // - Returns the mean of all values stored in the array. double mean(const double array[], int arraySize); // - Passes in an array, the size...
use matlab to solve it 1. Write a function called MyTimeConversion with the following function declaration line. begin code function [Hours, Minutes, Message] = MyTimeConversion (TotalMinutes) end code The input argument TotalMinutes should be a nonnegative scalar integer representing the total number of minutes in a specified time interval. The output arguments Hours and Minutes should be nonnegative scalars such that Hours*60 + Minutes = TotalMinutes and the value of Minutes must be less than 60. The output argument Message...
Homework Question Write a void function called transformArray that takes two parameters - a reference to a pointer to a dynamically allocated array of ints, and the size of that array. The pointer is passed by referencebecause you want to change the value of the pointer. The function should dynamically allocate an array that is twice as long, filled with the values from the original array followed by each of those values times 2. For example, if the array that was...
Please answer problem #5 thank you str.c #include "str.h" #include <stdio.h> int str_len(char *s) { /* this is here so code compiles */ return 0; } /* array version */ /* concantenate t to the end of s; s must be big enough */ void str_cat(char s[], char t[]) { int i, j; i = j = 0; while (s[i] != '\0') /* find end of s */ i++; while ((s[i++] = t[j++]) != '\0') /* copy t */ ;...
#include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...