×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

last post re: sort func. is fixed; nedd help with read/write funcs.

last post re: sort func. is fixed; nedd help with read/write funcs.

last post re: sort func. is fixed; nedd help with read/write funcs.

(OP)
I posted last night regarding my sort function, however, it turns out that wasn't the problem at all, it was my write function.  I have since fixed that problem within my write function.  The problem I'm dealing with now, is that my read func. seems not to be getting the final number from my input file.  I've pasted both my read and write funcs. below.  (in case it's actually a write error).  The output is good, except that it excludes that final number.

void read (istream& in_str, int arr[], int size, int& num_used)
{

    for(int index = 0; index < size-1 && in_str >> arr[index]; index++)
   {
        num_used = index;
   }//end for
}//end read

void write (ostream& out_str, int arr[], int size, int& num_used)
{
   for (int index = 0; index < size && index < num_used; index++)
   {
       out_str << arr[index];
      out_str << " ";
   }
   out_str << endl;
}

RE: last post re: sort func. is fixed; nedd help with read/write funcs.

I suggest that although your "for" statement looks very sophisticated, it may be unduely comlicated and could be causing the problem.  C++ does not guarentee the order in which "AND" operations are performed.  Break the "for" down to just the Index < limit, and add a "break" statement inside the loop at the appropreate time to exit the "for" loop.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close