Clinton Portis 211 Practically a Posting Shark

try turning all the -> into periods .

I can give you the explaination for this later on if you desire.

ok i'll give it to you now:

to keep it simple: whenever you are using a subscripted pointer, the pointer is automatically dereferrenced, therefore, you do not need to use the arrow operator.

(except when you are using an array of pointers)

Clinton Portis 211 Practically a Posting Shark

Very good.

One recommendation though, I would place your ignore() before the getline() call in efforts to clear the input buffer of any extraneous pesky newline characters.

In fact, if you don't do this, it will adversely affect your program later on.

Also, in keeping with good programming practices, move line #39 to line #28. All variable declarations should be made together at the beginning of a block of code. (having variables declared at random throughout your code will turn it into a nightmare)

So this brings us to step #8:

8. Call the function GetStudents from main.

I have full confidence in your ability to make the function call as required. As soon as you are done with this, we can move on to step #9.

Clinton Portis 211 Practically a Posting Shark

6. Now create an array of 2 structures in main. Call the array Students.

StuName Students[2];

Very good. Incorrect, but very close:

//Step #6
Student Students[2];

This brings us to step #7

7. Create a function, GetStudents, which will receive the array and an int representing the number of elements(2).

void GetStudents(Student array[], int size)
{
     for(int i=0; i<size; i++)
     {
          cin.ignore(1);

          cout << "Enter name: ";
          cin.getline(array[i].Name, 30);

          cout << "Enter GPA: ";
          cin >> array[i].GPA;

          cout << "Enter major: " ;
          cin >> array[i].Major;          
     }
}

Please make the appropriate addition of this function to your code as per step #7 requirement. Include function prototype, function call, and function definition.

As soon as you are done, we can move on to step #8.

Clinton Portis 211 Practically a Posting Shark

Here is the requirement:

6. Now create an array of 2 structures in main. Call the array Students.

Here is your code:

int students[Num_Student] = {"Student 1", "Student 2"};

You've successfully managed to declare an array of integers.

Q: How do you think you'd declare an array of 'Student' objects?

Clinton Portis 211 Practically a Posting Shark

What you have up there is good stuff....

Now let's move on to bigger and better things.. like creating an array of two student objects inside of main() (step #6)

Clinton Portis 211 Practically a Posting Shark

You are re-inventing the wheel by creating another function (show)...... that does the same thing as an existing function that we worked so hard to create (display)...

Why do you insist on doing extra work? Isn't the point of OOP code re-use..?

Clinton Portis 211 Practically a Posting Shark

If you are not sure what your professor is trying to teach you..... I'll tell you.

In the beginning, S1 and S2 are the same.

You show your mastery of c++ by changing the S2 object

Now you can show the world that S1 no longer is the same as S2

But all this is stuff you don't even have to worry about.

Your professor is the customer.

Whatever he wants, he gets.

Even if it doesn't make sense.

Keep your mind on the assignment requirements.

Everything else is B.S.

Your project is correct thus far.

Please in (insert devine figure name here)'s name, just complete step #6 sometime before midnight.

Clinton Portis 211 Practically a Posting Shark

Yess... you got it.

You made an additional display() call after the S2 object was affected at ChangeData().

So, here is our good working code that compiles and adheres to the assignment requirements:

#include<iostream>
using namespace std;


struct Student
{
     char Name[30];
     float GPA;
     int Major;
};

//Function prototypes
Student* StudentData(Student* S);
void display(Student* S);
void ChangeData(Student* S);


//main driver
int main()
{
     //Declare two objects of type 'Student'
     Student* S1 = new Student;
     Student* S2 = new Student;

     //Pass this object into our function so it can be filled up with useful information; step #2
     S1 = StudentData(S2);
     //Display new and exciting information to the DOS console; step #3
     display(S1);
     display(S2);
     //Function call to change data in S2 as per step #4 requirement
     ChangeData(S2);
     //Function call to dsiplay the newly changed S2 object as per step #5
     display(S2);


return 0;
}


//Function Definitions
Student* StudentData(Student* S)
{
     cout << "Enter name: ";
     cin >> S->Name;

     cout << "Enter GPA: ";
     cin >> S->GPA;

     cout << "please enter major" ;
     cin >> S->Major;

     return S;
}

void display(Student* S)
{
    cout << S->Name  << endl;
    cout << S->GPA   << endl;
    cout << S->Major << endl;
}

void ChangeData(Student* S)
{
     cout << "Enter name: ";
     cin >> S->Name;

     cout << "Enter GPA: ";
     cin >> S->GPA;

     cout << "please enter major" ;
     cin >> S->Major;
}

This brings us to step #6:

6. Now create an array of 2 structures in main. Call the array Students.

Easy …

Clinton Portis 211 Practically a Posting Shark

Because your assignment requires you to.....

3. In main print the data stored in the structures S1 and S2 using cout.

Clinton Portis 211 Practically a Posting Shark

You still haven't made any attempt to display the contents of the S2 object since it was affected at the ChangeData() function call.

I am not going to help you any further until you do so.

Clinton Portis 211 Practically a Posting Shark

Excellent, we have completed step #4. Here is our good working code that compiles based on steps 1 thru 4:

#include<iostream>
using namespace std;


struct Student
{
     char Name[30];
     float GPA;
     int Major;
};

//Function prototypes
Student* StudentData(Student* S);
void display(Student* S);
void ChangeData(Student* S);


//main driver
int main()
{
     //Declare two objects of type 'Student'; step #1
     Student* S1 = new Student;
     Student* S2 = new Student;

     //Pass this object into our function so it can be filled up with useful information; step #2
     S1 = StudentData(S2);
     //Display new and exciting information to the DOS console; step #3
     display(S1);
     display(S2);
     //Function call to change data in S2 as per step #4 requirement
     ChangeData(S2);

return 0;
}


//Function Definitions
Student* StudentData(Student* S)
{
     cout << "Enter name: ";
     cin >> S->Name;

     cout << "Enter GPA: ";
     cin >> S->GPA;

     cout << "please enter major" ;
     cin >> S->Major;

     return S;
}

void display(Student* S)
{
    cout << S->Name  << endl;
    cout << S->GPA   << endl;
    cout << S->Major << endl;
}

void ChangeData(Student* S)
{
     cout << "\nEnter name: ";
     cin >> S->Name;

     cout << "Enter GPA: ";
     cin >> S->GPA;

     cout << "please enter major" ;
     cin >> S->Major;
}

Now this brings us up to step #5:

5. Back in main print the data stored in the structure S2 using cout.

THIS IS EASY.... just make a simple function call inside of main()..

We already have the function available to us.. all you have to do …

Clinton Portis 211 Practically a Posting Shark

Thank you. So this is how our program looks 3 steps into your project. It isn't much, but it is a working good program that compiles with no errors and gives us expected repeatable performance:

#include<iostream>
using namespace std;


struct Student
{
     char Name[30];
     float GPA;
     int Major;
};

//Function prototypes
Student* StudentData(Student* S);
void display(Student* S);

int main()
{
     //Declare two objects of type 'Student'
     Student* S1 = new Student;
     Student* S2 = new Student;

     //Pass this object into our function so it can be filled up with useful information
     S1 = StudentData(S2);
     //Display new and exciting information to the DOS console
     display(S1);
     display(S2);


return 0;
}


//Function Definitions
Student* StudentData(Student* S)
{
     cout << "Enter name: ";
     cin >> S->Name;

     cout << "Enter GPA: ";
     cin >> S->GPA;

     cout << "please enter major" ;
     cin >> S->Major;

     return S;
}

void display(Student* S)
{
    cout << S->Name  << endl;
    cout << S->GPA   << endl;
    cout << S->Major << endl;
}

I tried to avoid having everything pointered out... but I think that's the way we are going to have to go with this.

Ok, so we are at step #4:


4. Call a function named ChangeData with a pointer to S2 as the argument:
ChangeData( &S2 ); //this is the call to the function
Change the data in S2 so that the GPA is 3.0 and the Major is 1. (Using these values for testing…)

This part I will make so easy …

Clinton Portis 211 Practically a Posting Shark

i think the reason why im having so much trouble is because its due today and i am rushing to remember but cant

this isn't my fault.

Clinton Portis 211 Practically a Posting Shark
  • What you wrote, is not close.
  • Please.. take another look at the StudentData() function.
  • It will be almost identical to our display function BUT WITHOUT THE CIN'S.
  • Take a look at my code. Your code should look like my code.
  • Once you are comfortable with how a normal c++ program should look, feel free to attempt to write a "display()" function.
  • The function will accept a reference to a 'Student' type object.
  • The function will 'cout' all attributes of the Student object.
  • As soon as you can do this, we can move on to step #4.
  • But for now, we are stuck at step #3.

Now amaze us with your coding ability.

Clinton Portis 211 Practically a Posting Shark

Take another look at how data is formatted inside of our StudentData() function and try again....

(and why are you using array subscripts..??!??!)

Like I said before, the display() function is going to look very similar to the StudentData() function (but since we are displaying only, it will only use cout statements)... so don't over complicate this shizzle.

Clinton Portis 211 Practically a Posting Shark

You do not have to use anything other than the <iostream> library to send output to the dos console.

3. In main print the data stored in the structures S1 and S2 using cout.

We've wrote one function so far.

I want you to try writing another function.. one that will take a reference to a 'Student' type object and display it's contents. The function will look similar to the one we have just written; however, it will only contain cout << commands.

This will be your display function outline:

void display(Student& S)
{
     //Suprise me with your hidden c++ talents
     //Display all atributes of the 'student' object here...
}
Clinton Portis 211 Practically a Posting Shark

Actually, this will satisfy the requirement for step #1 & #2:

#include<iostream>
using namespace std;


struct Student
{
     char Name[30];
     float GPA;
     int Major;
};

//Function prototypes
Student* StudentData(Student& S);

int main()
{
     //Declare two objects of type 'Student'
     Student* S1, S2;

     //Pass this object into our function so it can be filled up with useful information
     S1 = StudentData(S2);

return 0;
}

//Function Definitions
Student* StudentData(Student& S)
{
     cout << "Enter name: ";
     cin >> S.Name;

     cout << "Enter GPA: ";
     cin >> S.GPA;

     cout << "please enter major" ;
     cin >> S.Major;

     return &S;
}

Now we are at step #3. I know you are probably not an expert at c++, but sir, can you tell me in english how you would go about accomplishing the 3rd step of the task at hand...

Clinton Portis 211 Practically a Posting Shark

How the code works should not be a mystery... but I will break it down for you.

What we are writing is called a "function".

The purpose of this function (as per your requirement) is to be able to accept an object of type 'student' and populate it's contents. We will then return a reference to the object (as per your requirement)

So, this is what we should have so far at step #2:

#include<iostream>
using namespace std;


struct Student
{
     char Name[30];
     float GPA;
     int Major;
};

//Function prototypes
Student* StudentData(Student& S);

int main()
{
     //Declare an object of type 'student'
     Student myStudent;

     //Pass this object into our function so it can be filled up with useful information
     StudentData(myStudent);

return 0;
}

//Function Definitions
Student* StudentData(Student& S)
{
     cout << "Enter name: ";
     cin >> S.Name;

     cout << "Enter GPA: ";
     cin >> S.GPA;

     cout << "please enter major" ;
     cin >> S.Major;

     return &S;
}

So at this point, we have a good working code that compiles and completes the requirements for step #2.. it isn't much, but it is something to build on.

Clinton Portis 211 Practically a Posting Shark

well I've populated the first two attributes of the student struct for you.. let's see if you can at least make an attempt to populate the third attribute:

/* please, by all means.. just take a guess at how you would go about getting information from the user and storing into the 3rd (and last) attribute of the student struct: */

//Here is how we populated the first 2 attributes...

Student* StudentData(Student& S)
{
    cout << "Enter name: ";
    cin >> S.Name;

    cout << "Enter GPA: "
    cin >> S.GPA; 

     //At least take a guess at what would go here
}

when you make effort.. i'll make effort.

Clinton Portis 211 Practically a Posting Shark

As per the c++ tutorial for accepting user input, try adding this line after line #24:

cin.ignore(100, '\n');
Clinton Portis 211 Practically a Posting Shark

then how about this..??

void TicTacToe::postMove(int row, int col, char value)
{
     theboard[row-1][col-1] = value; 
     showBoard();
}
Clinton Portis 211 Practically a Posting Shark

You've brought up a good point; the >> extraction operator is 'white space' delimeted.

If you want to read the entire line, try using the getline() function from <string>

#include<string>

getline(cin, employee[counter].name);
Clinton Portis 211 Practically a Posting Shark

Why have you made no attempt at populating the 3rd attribute of your Student struct.?

Clinton Portis 211 Practically a Posting Shark

Why ruin a good thing you already got goin'?

//this
gets(employee[counter].name);
//should be this
cin >> employee[counter].name;

I am really not sure where you got "gets()" from.. I think it's a C function... and if I'm not mistaken it's use can be somewhat dangerous.

In my opinion, it is time to remove the gets() function from your c++ repertoire as I have never seen it's use in any code thus far in this forum... or in any other c++ code I have ever seen.

Clinton Portis 211 Practically a Posting Shark

You will probably want to take some time one day and study the http://www.winprog.org/tutorial/bitmaps.html.

Also, since you are operating in a DOS console environment, be sure to check out adrianwx's windows programming for DOS tutorial.

Although I am not sure if one can load a bitmap to a dos console (i'm somewhat intruiged by this and am currently thinking of possibilities) here is a basic standard code for loading a bitmap in a win32 application:

//Just to give you an idea of what you are about to get into
#include<windows.h>

   HBITMAP g_hbmBal = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BALL));
        
   if(g_hbmBall == NULL)
        MessageBox(hwnd, "Could not load IDB_BALL!", "Error", MB_OK | MB_ICONEXCLAMATION);




   BITMAP bm;
   PAINTSTRUCT ps;

   HDC hdc = BeginPaint(hwnd, &ps);

   HDC hdcMem = CreateCompatibleDC(hdc);
   HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);

   GetObject(g_hbmBall, sizeof(bm), &bm);

   //Here is where the bitmap is drawn to the window
   BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

   SelectObject(hdcMem, hbmOld);
   DeleteDC(hdcMem);

   EndPaint(hwnd, &ps);
Clinton Portis 211 Practically a Posting Shark

I appologize for my indescretions, but i got distracted with other things, so here is a function for you, free of charge. No effort at learning required on your part:

/* pass the array to a function that takes an array of integers, its size and n and returns the value that was repeated more than other values. The function must use an array of n elements that is used to store the number of occurrences of a specific value, for example location 0 tells you how many times 0 appeared in the passed array, location 1 tells you how many times 1 appeared in the passed array and so forth. */

#include<algorithm>

int high_frequency(int array[], int& size, int& n)
{
     int highest = 0;
     int temp = 0;
     int index = 0;
     int* counter = new int[n];

     fill(&counter[0], &counter[n], 0);

     for(int i=0; i<size; i++)
     {
          temp = count(&array[0], &array[size], array[i]); 

          if(temp > highest)
          {
               highest = temp;    
               index = i;           
          }

          counter[array[i]] = temp;
     }

     return array[index];
}
Clinton Portis 211 Practically a Posting Shark

This one is pretty decent:

http://www.codeblocks.org/

Not as easy as it used to be.. you could easily start a 'project' as opposed to a 'c++ source' which will mess things up. The debugger is kinda wack. Also, it forces you to save work you haven't even created yet.

If you can get past all that, it's a pretty decent IDE.

Clinton Portis 211 Practically a Posting Shark

would this be anything close to what you need...?

void TicTacToe::postMove(int row, int col, char value)
{
     theboard[row][col] = value;
     showBoard();
}
Clinton Portis 211 Practically a Posting Shark
//Write a program that creates an array dynamically whose pointer must not change
const int* array = new int[size];

//initialize the array to random values between 0 and n (inclusive) using rand () 
for(int i=0; i<size; i++)
     array[i] = rand()%(n+1);

//then pass the array to a function that takes an array of integers, its size and n and returns the value that was repeated more than other values
int high_frequency(int array[], int& size, int& n)
{
     int highest = 0;
     int temp = 0;

     for(int i=0; i<size; i++)
     {
          temp = count(&array[0], &array[size], array[i]);
     
          if(temp > highest)
 
               highest = temp;
     }
Clinton Portis 211 Practically a Posting Shark

Move on through your C++ at a rate at which you understand the material (for the most part) and then begin to tackle the next concept.

Clinton Portis 211 Practically a Posting Shark

I would be more than happy to help you.. however, I cannot read a bit of that antiquated C code that you have posted in this C++ forum...

Clinton Portis 211 Practically a Posting Shark

Here is recent help given to one of your classmates:

http://www.daniweb.com/forums/post1070744.html#post1070744

trcartmill commented: Thank you, That helps me out on the right track. but im getting errors in the compiler that is: could not deduce template argument and expects 2 arguments, 3 provided. it would be line 8 in your code. +0
Clinton Portis 211 Practically a Posting Shark

int main(){return 0;}

Clinton Portis 211 Practically a Posting Shark

New and improved version:

#include<iostream>
#include<string>
#include<fstream>
#include<windows.h>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
    //var declarations
    int length = 0;
    char* buffer = new char[17];
    buffer[16] = '\0';
    vector<char*> cstrings;

    //create ifstream object for reading from a file
    ifstream infile;

    //attempt to open a file
    //in this case, since we are dealing mostly with ascii chars
    //it is better to open in regular default ascii mode.
    infile.open("C:\\Users\\Dave\\Documents\\test.txt");

    //perform error checking
    if(!infile.is_open())
    {
        cout << "\aError opening file!";
        cin.get();
        exit(EXIT_FAILURE);
    }

    int i=1;
    //read in file in 16 byte segments, or as much is left until end of file
    while(infile.readsome(buffer, 16))
    {
        //take out '\n' newlines for console formatting purposes
        replace(&buffer[0], &buffer[16], '\n', ' ');
        //display exciting information to the user
        cout << "\n\nBock #" << i << ": " << buffer;
        cout << "\nChar count: " << infile.gcount();
        //save our buffer in an 'array type' STL container
        cstrings.push_back(buffer);
        //create new buffer
        buffer = new char[17];
        //ensure 'cstring style' null termination
        buffer[16] = '\0';
        //perform sleep operation
        Sleep(500);
        //step up the block number
        i++;
    }

    //close the ifstream object since we no longer need to read from a file
    infile.close();

    return 0;
}
Clinton Portis 211 Practically a Posting Shark

Check this out and see if you have any questions about this working program:

#include<iostream>
#include<string>
#include<fstream>
#include<windows.h>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
    //var declarations
    int length = 0;
    char buffer[17];
    vector<char*> cstrings;

    //create ifstream object for reading from a file
    ifstream infile;

    //attempt to open a file 
    //in this case, since we are dealing primarily with ascii chars
    //it is better to open in regular default ascii mode.
    infile.open("C:\\Users\\Dave\\Documents\\test.txt");

    //perform error checking
    if(!infile.is_open())
    {
        cout << "\aError opening file!";
        cin.get();
        exit(EXIT_FAILURE);
    }

    int i=1;
    buffer[16] = '\0';
    //read in file in 16 byte segments, or as much is left until end of file
    while(infile.readsome(buffer, 16))
    {        
        //take out '\n' newlines for console formatting purposes
        replace(&buffer[0], &buffer[16], '\n', ' ');
        //display exciting information to the user
        cout << "\n\nBock #" << i << ": " << buffer;
        cout << "\nChar count: " << infile.gcount();
        //save our buffer in an 'array type' STL container
        cstrings.push_back(buffer);
        //perform sleep operation
        Sleep(500);
        //step up the block number
        i++;
    }

    //close the ifstream object since we no longer need to read from a file
    infile.close();

    return 0;
}
Clinton Portis 211 Practically a Posting Shark

Although I am not an <sstream> expert (don't use it that much) I am kinda skeptical about this code:

while(Read.get(buffer[i], 17))
{
     for(j=0; j<=16; j++)
     oss << buffer[i][j];

It seems to me like you are continually just overwritting the value inserted into your 'oss' object... to me, this would seem a more viable method:

while(Read.get(buffer[i], 17))
{
     oss << buffer[i];
     cout << "Contents : " << oss.str() << endl;
     i++;
}
Clinton Portis 211 Practically a Posting Shark

Also, why are you posting C code in a C++ forum..??!

Clinton Portis 211 Practically a Posting Shark

You appear to be lost and overwhelmed held captive in a class that probably has no relevance whatsoever to your degree major.

What you need is a strategy to tackle this seemingly overwhelming task.

If you look at this thing in it's entirety, yes.. it does look like some intense work. The key is to break it down as simple as possible, one step at a time.

Tip: Don't even worry about implementing error handling until you have at least a good working code. It's easy to add it in at the end once you have the main project complete.

I suspect you can perform step #1. But I'm sure you'll probably be asking what the heck you need to do for step 2.

Here is the main requirement for step #2:

2. Create and call a function named StudentData:
S2 = StudentData( S1 ); //this is the call to the function
The function receives as a parameter a reference to the structure (prototyping will handle this) and will return a reference to the structure. Use couts and cins for getting data from the user.

The requirement tells you everything you need to do, so there is no guesswork... all you have to do is translate the requirement into c++. Write a function that accepts arguments and required by your instructor, prompt the user to change stuff, and return a reference to the object passed into your function.

Student* StudentData(Student& S)
{ …
Clinton Portis 211 Practically a Posting Shark

I found this article at msdn:

The multiplicative operators take operands of arithmetic types. The modulus operator (%) has a stricter requirement in that its operands must be of integral type. (To get the remainder of a floating-point division, use the run-time function, fmod.) The conversions covered in Arithmetic Conversions are applied to the operands, and the result is of the converted type.

According to the article, you might have better luck using the fmod() function from <cmath>.

Clinton Portis 211 Practically a Posting Shark

You seem interested in reading in a file until you reach a delimeting comma. In this case, I recommend use of getline().

There are a few different getline() functions floating around in the c++ world. The one we are using (and most popular in file i/o) is derived from the <string> library:

#include<string>

string town[20];
double ave_temp[20];
int population[20];

int i=0;
while(getline(In, town[i], ','))
{
     //these are "white space" delimeted
     in >> ave_temp[i];
     in >> population[i];
     i++;
}

I attempted to use getline then parse the array to strip out the comma,

Being the astute CS student that you are, I am sure that you've already studied the documentation for the getline() function and found out that it extracts and discards any delimeting characters:

getline

function<string>istream& getline ( istream& is, string& str, char delim );
istream& getline ( istream& is, string& str );
Get line from stream

Extracts characters from is and stores them into str until a delimitation character is found.

The delimiter character is delim for the first function version, and '\n' (newline character) for the second. The extraction also stops if the end of file is reached in is or if some other error occurs during the input operation.

If the delimiter is found, it is extracted and discarded, i.e. it is not stored and the next input operation will begin after it.

So today, we used a version of the overloaded <string> library function called getline(). The version …

Clinton Portis 211 Practically a Posting Shark

You seem to have mentioned that you have attepted to make some sort of effort at seeking a solution to the problem. I'm sure myself and others would be highly interested in seeing what you have come up with thus far; thereby seperating yourself from the masses of "please do this for me" laziness that we are so often subjected to on a daily basis.

mrnutty commented: Indeed. +2
Clinton Portis 211 Practically a Posting Shark

I have everything I need in the code except the "between 100 and 1000."

//Line #28 should be this:
popList[i] = rand( ) % 901 + 100  ;
Clinton Portis 211 Practically a Posting Shark

After briefly looking at your code.. maybe all it needs is just a space in between commands:

//this
strcpy(str, "taskkill /f /im");
//might work if it was like this:
strcpy(str, " taskkill /f /im");
Clinton Portis 211 Practically a Posting Shark

Just add a sleep function of some sort in the file reading loop (after line#19 perhaps).. otherwise, the above code will meet your stringent requirements, reading the file contiguously from the point it left off.

Clinton Portis 211 Practically a Posting Shark

@ Clinton Portis :

I tried using seekg(), but my intended output was much different. Could you look into this?

http://pastebin.com/f6bc14999

without even looking, I will guess that your file has not been opened in binary mode; in which case, I would highly recommend doing so whilst messing about with file pointers.

[Edit]
Ok.. you opened in binary.. I'll look into this a bit and see if I see anything.

Line#19: You are reading the file based on the current condition of the eof() fail bit flag, not recommended.

Lines#27 thru #33: You are attempting to seekg() to your current position....... which, you are already at :rollseyes:

I am going to make a few assumptions here and attempt to help you out.

1. You are attempting to read in the file in a contiguous manner.
2. You would like to break up the file into 16byte chunks.

With this in mind, we can focus strictly on the task at hand:

//Get the size of the file
Read.seekg(0, ios::end);
length = Read.tellg();
Read.seekg(0, ios::beg);

//Create a buffer to meet our needs
char* buffer = new char*[length];
for(int i=0; i<length; i++)
{
     buffer[i] = new char[17];
     buffer[i][16] = '\0';
}

//Read the file in 16byte segments or eof(), whichever comes first
//Testing the return condition of the function is preferred, as opposed to testing eof()
int i=0;
while(Read.get(buffer[i], 16))
{
     i++;
}

There you have it... simple, straight forward, no unecessary …

Clinton Portis 211 Practically a Posting Shark

I am glad you asked. Use the seekg() function to move about in your file as ye' wish:

istream::seekg

public member functionistream& seekg ( streampos pos );
istream& seekg ( streamoff off, ios_base::seekdir dir );
Set position of the get pointer

Sets the position of the get pointer.
The get pointer determines the next location to be read in the source associated to the stream.


Parameters

pos
The new position in the stream buffer. This parameter is an integral value of type streampos.

off
Integral value of type streamoff representing the offset to be applied relative to an absolute position specified in the dir parameter.

dir
Seeking direction. It is an object of type ios_base::seekdir that specifies an absolute position from where the offset parameter off is applied. It can take any of the following member constant values:
value offset is relative to...

ios_base::beg beginning of the stream buffer
ios_base::cur current position in the stream buffer
ios_base::end end of the stream buffer

Return Value
The function returns *this.

So just call a seekg(position) whenever you want to set the 'get pointer' to a position where ye' would like to start reading from the file. Then I would call the readsome() function to read in a chunk of the file.

Keep in mind, if you are reading the file in a contiguous manor, the 'get pointer' will be at the position where you left it, in …

Clinton Portis 211 Practically a Posting Shark

You may want to check this out before posting homework.

Clinton Portis 211 Practically a Posting Shark

If you are referring to the file i/o implementation, I would like to argue to your professor that reading the entire file at once is more efficient than reading 'line by line' or 'word by word' or 'char by char'. Additionally, the use of a dynamically allocated buffer increases efficiency due to not needing to 'over guess' the amount of space needed by statically creating an array of an arbitrary size.

If you are referring to the array comparison algorithm, I am unaware of anything that will provide you with the results you need with anymore efficiency than performing an 'element by element' comparison.

Clinton Portis 211 Practically a Posting Shark

I'm trying to do a concatenation function I do not want to you use the strings property where we can add strings, I need to add two strings and save them in one string without the use of addition "+"

Instead of trying to decipher your code, I will offer a pseudo-coded solution:

char* concat(string& first, string& second, char* buffer);

string first = "We think in generalities ";
string second = "but we live in details.";

char* concat(string& first, string& second, char* buffer)
{
     int length = 0;

     //Get length of first string
     length = first.size();

     //Add to length of second string
     length += second.size();

     //Allocate enough memory for a cstring buffer
     buffer = new char[length+1];

     //Ensure cstring null termination
     buffer[length] = '\0';

     //Perform concantination
     int i=0;
     while(first[i] != string::npos)
     {
          buffer[i] = first[i];
          i++;
     }
     int j=0;
     while(second[j] != string::npos)
     {
          buffer[i] = second[j];
          i++;
          j++;
     }

     return buffer;
}
Clinton Portis 211 Practically a Posting Shark

I have to read 16 bytes using the low-level function call read() (in C). After I read the first 16 bytes, the next time I need to read from the same file, I'll only have to read it from until the point it was read before..

Since you only require to read in a certain amount of the file (as opposed to reading in the entire file at once) I think readsome() function may be a more appropriate choice:

istream::readsome

public member function

streamsize readsome ( char* s, streamsize n );

Read block of data available in the buffer
Reads a block of data of up to n characters and stores it in the array pointed by s, but unlike member function read, readsome stops reading if the memory buffer associated with the stream runs out of characters, even if the End-Of-File has not yet been reached.

Return Value
The number of characters extracted.

Errors are signaled by modifying the internal state flags.

With this in mind, I would propose using the readsome() function and reading the file into a char[16] buffers (or char[17] if you would like to provide null termination which will allow you to use <cstring> functions safely)

Since you would probably need to use several char[16] buffers, let's create a bunch of them:

char buffer[100][16];

A more optimal alternative of course, would be to dynamically create an array of specific size based on the number of characters in your file:

halluc1nati0n commented: Good ideas.. +1