Duoas 1,025 Postaholic Featured Poster

Here's a wild stab in the dark: you are using a really old compiler like Turbo C.

If I'm right, then you should visit one of the following and get yourself a compiler that makes 32-bit executables:
http://www.mingw.org/
http://www.turboexplorer.com/
http://www.microsoft.com/express/vc/

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

It has nothing to do with the function. It is flashing because the DOS emulator is lagging when your code updates the screen.

Now that my brain is working, though, if you are trying to do animations stay away from cleardevice().

There are two little functions to set the active page and the displayed page (I don't remember their names right now... but you can look them up).

The trick is this:
1. set the active page to whichever page is currently hidden
2. clear, draw, etc... whatever you need to do to create the next frame of animation
3. set the visible page to the active page
4. rinse and repeat

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You aren't erasing the iterator, you are erasing the contents of your map.

An iterator is practically always a locally-constructed variable, so you don't have to worry about destructing it. From your point of view (the programmer) you can consider an iterator the same as a pointer into a container (in this case, the map).

The following two codes are analogous:

char s[] = "Hello world!";
char* p;
for (p = s; *p != '\0'; p++)
  *p = toupper( *p );
string s = "Hello world!";
string::iterator p;
for (p = s.begin(); p != s.end(); p++)
  *p = toupper( *p );

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Using the old BGI functions you are pretty much out of luck... Sorry.

Are you using an old Turbo C compiler or are you using the WinBGIm package?

Duoas 1,025 Postaholic Featured Poster

You only made one error:
1. Tests to see if the variable trial is evenly divisible by the next prime number in the array
2. yep
3. yep
4. yep

C++ has a native boolean type (bool, of course) but in C-related languages any non-zero value is considered true. Hence, saying: if (foo) is exactly the same as saying: if (foo != 0) (or in C++: if (foo != false) ).

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You know, if you are willing to play with some assembly language, you can link it into GWBASIC and do what you want...

Antonis's GWBASIC User's Manual

(But it is probably more worth the effort just to port it to VB.)

Duoas 1,025 Postaholic Featured Poster

I agree. If it isn't a boolean value, I (almost) always state the condition explicitly.

C, and consequently C++, lend themselves to a lot of "shortcuts" in style. After a while you will get used to looking at the funny jumble of punctuation and understand it easily enough.

Some people, however, like to take it waaay past readability. Ever hear of the IOCCC? It's enough to make anyone's head swim.

Sure is fun though. :)

Duoas 1,025 Postaholic Featured Poster

Every version of python I've ever gotten (including the last three) came with DLL files.

C:\WINDOWS\system32>dir python*.dll
 Volume in drive C is Ceres
 Volume Serial Number is 0000-0000

 Directory of C:\WINDOWS\system32

02/08/2005  05:23 PM           979,005 python23.dll
10/18/2006  09:35 AM         1,871,872 python24.dll
02/21/2008  01:11 PM         2,117,632 python25.dll
               3 File(s)      4,968,509 bytes

You are using Windows, right? Because Linux doesn't use DLLs natively.

Duoas 1,025 Postaholic Featured Poster

You've got the general idea.

The % sign is the modulo (or remainder) operator. So what it is saying is:

"If the number I am looking at (trial) divides evenly by the indexed prime (which should have been written as primes[ [B][/B]i[B][/B] ] to be less confusing), then we have found a composite number."

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I think by this point AD is tired of answering the same question the same way again and again and again...

If you want the machine code for the function, tell your compiler to output the assembly code, chop off everything except the function, and run it through your assembler, or plug the opcodes directly into DEBUG (and the DOS prompt) and save the codes to file.

Duoas 1,025 Postaholic Featured Poster

It makes perfect sense. You just need to think about it a little more. I don't intend to post back again just to argue what MCM is supposed to do.

As for p, I understand how matrix multiplication works. Don't be fooled by the nonsense numbers I used above in the example. I suppose you can do it that way, but I think you are making more work for yourself than you have to...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

No. With some old BASICs you can play with the SCREEN command to set the window mode, but GWBASIC doesn't understand anything but CGA modes...

Also, the forum you want is Legacy and Other Languages.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

2. It is entirely possible that I have misunderstood something about your question. It isn't actually very clear. I know you are frustrated by a stack overflow with your posted algorithm. I have largely ignored that part because:

1. You have definitely misunderstood the MCM.


MCM does not give you the quotient matrix. It only computes the optimal way to multiply the matrices together.

So your MCO procedure corresponds to the actual Matrix Chain Multiplication algorithm. Except that it doesn't properly work.

Firstly, p is incorrect. You cannot ignore the number of rows for each matrix but the first. Also, your loops look a little wonky to me. I haven't traced through them, but there are a couple of things that make them very suspect to me. I suggest you spend some time reconsidering how they work.

Secondly, your last two procs assume something about the data in the split table -- it acts properly on only one of the two possibilities.


The reason I went through all that above is because I want you to forget the pseudo-code stuff someone else gave you and to think about the way the algorithm works on your own. I want you to do this because it is what you need to do to really fix the underlying problems you are having with the code.

As to the stack overflow, if your matrices are of any considerable dimensions then each one chews up …

Duoas 1,025 Postaholic Featured Poster

OK, since no one else is looking at this one... (I had to go learn to do the Matrix Chain Multiplication)

I think you are missing something here.
The MCM algorithm isn't actually supposed to multiply the matrices together.
It is just to tell you the best order in which to multiply the matrices.

Once you know the order, then you can do the multiplications.

The other trick is a sneaky one: that sl matrix you've got there is a dirty trick to replace a binary tree. Except it is missing something: links to the next node. Meaning you need another matrix to track that information.


To review the algorithm, then, using our matrix/binary-tree substitutes, it should work something like the following example illustrates.

Given: A1 x A2 x A3 x A4
where

  • A1 is 2 rows by 3 columns
  • A2 is 5 rows by 10 columns
  • A3 is 10 rows by 7 columns
  • A4 is 50 rows by 5 columns

Question: What is the best way to parenthesize this equation? (Or, which two matrices do I multiply together first, then which one do I multiply with that, etc)

(Sorry, but I don't know how to do subscripts with DaniWeb, so pretend that the 1,2,3,4 are subscripts to A.)

Since we've got four matrices to order, we need two 4 by 4 matrices: one to represent the best cost of multiplying some set, and another to indicate where to …

Duoas 1,025 Postaholic Featured Poster

I don't know.

If you know how to link windows resources to your project, create an icon resource named MAINICON.

Otherwise you'll have to use resource hacker.

Good luck!

Duoas 1,025 Postaholic Featured Poster

That was just an example function I created. I expected that you would take the code you needed from it and put it in your own function.

I don't think that TTextBox::Text takes a std::string, does it? You might have to say textBox1->Text = found.c_str(); Hope this helps.

zandiago commented: congrats on featured poster +6
Duoas 1,025 Postaholic Featured Poster

There is no particularly 'easy' answer, but you can use the STL to do it:

#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <deque>

// Our dummy class
template <int n>
struct column_n_t: public std::string { };

// Our dummy class input extractor
template <int n>
std::istream& operator >> ( std::istream& ins, column_n_t <n> & c )
  {
  std::string s;
  std::getline( ins, s );
  std::stringstream ss( s );
  for (int i = 0; i < n; i++)
    ss >> s;
  if (!ss) s.clear();
  c.assign( s );
  return ins;
  }

// A convenient function
template <int n>
std::deque <std::string> extract_column_n( std::istream& ins )
  {
  std::deque <std::string> result;

  std::copy(
    std::istream_iterator <column_n_t <n> > ( ins ),
    std::istream_iterator <column_n_t <n> > (),
    std::back_insert_iterator <std::deque <std::string> > ( result )
    );

  return result;
  }

Now to extract column three from the file:

std::deque <std::string> column_3 = extract_column_n <3> ( myfile );

This only works if you know which column you want to extract (3 is a constant) and if you know for sure that whitespace only appears between columns.

If either one of those preconditions are false some slight modifications will need to be made.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You can't use Int 21h or any other DOS interrupt service unless DOS (or WinXP or earlier) is running --hence the reason it works in the emulator and not in real-life.

The purpose of the OS is to manage software and provide access to hardware devices (such as disk drives). If you want your OS to work alone, you will have to include code to access the disk drives etc.

I suggest you read up on BIOS HD services you can use to access the hard drive etc.

Some reading on using the BIOS to access disk drives
http://www.pcguide.com/ref/hdd/bios/index.htm

BiosCentral
http://www.bioscentral.com/misc/biosservices.htm

Good luck.

Duoas 1,025 Postaholic Featured Poster

Use the FMUL opcode.

See 80x87 Instruction Set
HTML
PDF

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

This is the C++ forum. Are you sure you mean C functions and not C++?

Duoas 1,025 Postaholic Featured Poster

The string class does have methods specifically for doing that sort of stuff.
But you can use the standard algorithms just as easily.

#include <algorithm>   // needed by using_iterators()
#include <cctype>      // needed by using_iterators()
#include <functional>  // needed by using_iterators()
#include <iostream>
#include <iterator>    // needed by using_iterators()
#include <string>
using namespace std;

//------------------------------------------------
void using_iterators( string s, string w )
  {
  string::iterator i = search( s.begin(), s.end(), w.begin(), w.end() );
  if (i == s.end())
    {
    cout << "iterators> The text did not contain the word '"
         << w << "'.\n";
    return;
    }

  i = find_if( i +w.length(), s.end(), not1( ptr_fun <int,int> ( isspace ) ) );
  if (i == s.end())
    {
    cout << "iterators> There is no text following the word '"
         << w << "'.\n";
    return;
    }

  string::iterator j = find_if( i, s.end(), ptr_fun <int,int> ( isspace ) );
  string found;
  copy( i, j, back_insert_iterator <string> ( found ) );

  cout << "iterators> The word following '" << w << "' is '"
         << found << "'.\n";
  }

//------------------------------------------------
void using_indices( string s, string w )
  {
  string::size_type i = s.find( w );
  if (i == string::npos)
    {
    cout << "indices>   The text did not contain the word '"
         << w << "'.\n";
    return;
    }

  i = s.find_first_not_of( " \t", i +w.length() );
  if (i == string::npos)
    {
    cout << "indices>   There is no text following the word '"
         << w << "'.\n";
    return;
    }

  string::size_type j = s.find_first_of( " \t", i );
  string found; …
Duoas 1,025 Postaholic Featured Poster

Typically the main icon is linked in at compilation. How exactly you do it depends on your compiler. In all cases, a Windows resource named MAINICON is in your exe.

You can also check out Resource Hacker, which you can use to manually change a program's icon.

Duoas 1,025 Postaholic Featured Poster

If all you want is teletype output (like you get on the console, without any fancy graphics or fonts or etc) you can open the PRN or LPT1 device:

#include <fstream>
#include <iostream>
using namespace std;

int main()
  {
  ofstream printer( "prn" );

  if (!printer) 
    {
    cout << "fooey!\n";
    return 1;
    }

  printer << "Hello world!\n";

  printer.close();
  return 0;
  }

Most PC printers that I know of can handle simple TTY output of this kind. If you open in binary mode you can also send printer control codes (specific to your printer) to program it.

Have fun!

Alex Edwards commented: Great post, and sorry for giving you crap when I first joined. +1
scream2ice commented: thnx +1
Duoas 1,025 Postaholic Featured Poster

The best way to do that is to use a visual trick.

Capture an image of the button. (You can do this by using GetWindowDC() on your form, then using BitBlt() to transfer the image of the button into a TImage canvas.)

Actually hide the button.

In your form paint, draw the image of the button. Every few score milliseconds or so adjust your image to have more of the form's background color and repaint.

There are a number of ways you can fade the colors of an image with another given color with the Win32 API or by directly manipulating the pixel data yourself...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

If you are looking to port Win32 API code to Linux, take a look at Wine.

Duoas 1,025 Postaholic Featured Poster
Duoas 1,025 Postaholic Featured Poster

I've never used Dev-C++, but it should have a Windows MediaPlayer component that you can drop on your application, and use it to play the MP3.

You can also google "msdn media control interface" for the APIs you can use to manipulate media devices on Windows.

Good luck.

Duoas 1,025 Postaholic Featured Poster

This is an issue with DOS BOX, not C.

I recommend you visit the DOS BOX forums.
http://vogons.zetafleet.com/index.php?c=7

Good luck!

Duoas 1,025 Postaholic Featured Poster

The allocation thing is exactly your problem. The strings you are getting from the DLL are always invalid. :P

Please don't assume anything. A longstring -> PChar will always have a #0 appended, and a PChar -> longstring will always look for the #0 to terminate the string. How exactly are you testing for the #0?

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

If I remember correctly the Foo tutorials instruct you to get the pre-compiled binary DLLs.

It should have come with some header files. Did you put them in the include path? Did you tell VC++ where to find the lib files? Did you link with the SDL DLL?

Duoas 1,025 Postaholic Featured Poster

That's the way it is supposed to work. PChar is #0 terminated.

I would have to look it up to be sure, but I don't know if Delphi is smart enough to return a string the way you are doing it. The PChar you get from the DLL should be invalid.

The most proper way to do it (without the shared memory manager) would be to have your DLL export two kinds of function:

// type one: returns memory belonging to the DLL
function ReturnsAString: PChar;
function ReturnsAnotherString: PChar;
function ReturnsARecord: PSomeRec;

// type two: tell the DLL you are done with a piece of its memory
procedure FreeString( s: PChar );
procedure FreeSomeRec( r: PSomeRec );

The DLL should be allocating and deallocating dynamic memory to return its strings, etc, and the calling program should get and release access to that memory using the interface functions.

library MyDLL;
uses
  SysUtils;

const
  AString: string = 'Hello world!';

function ReturnsAString: PChar;
  begin
  GetMem( Result, length( AString ) +1 );
  StrPCopy( Result, AString )
  end;

procedure FreeString( s: PChar );
  begin
  FreeMem( s )
  end;

exports
  ReturnsAString,
  FreeString;

begin
end.

And your program should be using it thus:

procedure Button1Click( Sender: Object );  // or whatever
  var
    s: string;
    p: PChar;
  begin
  p := ReturnsAString;  // get the DLL's memory
  s := p;               // get a copy into our string
  FreeString( p );      // return the DLL's memory
  ShowMessage( s )
  end;

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes, use them in a loop. You should be looking at the mult and add opcodes.

Remember how a number is constructed: by powers of ten.

5 * 10^2 = 500
4 * 10^1 = 40
3 * 10^0 = 3

add them all up to get 543.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

You'll have to look through the documentation to see what you can do.

Besides lines and various shapes and bitblts and text there isn't much more BGI can do. It is a really old architecture, and DOS-centric.


I would actually suggest playing around with SDL. It is more powerful and multi-platform. (And very easy to use.) IMO, the WinBGI stuff is good for porting old Borland DOS graphics programs to work in Win32, but that's about it.


There's nothing wrong with it though. Just play around with it and think of what you would like to do.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Please use [[B][/B]code[B][/B]] tags.

You've declared the monthEnd() function as existing, but you don't appear to have defined it anywhere. If you prototype a function somewhere, there should be a corresponding function elsewhere.

When you compile, make sure to turn as many warning messages on as you can. The compiler should complain about missing functions.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

@Aggie
Your mirror() function is right-on.

However, in reverseList() you are still mixing siblings and children. The 'next' node is the sibling, not the child.

It took me a minute to figure it out because you used a whole bunch of nonsense variable names. I've been doing this for over twenty years. If it was hard for me to read then you don't stand a chance. Please use meaningful variable names.

@Alex
Swap is not useful here. Reversing a singly-linked list requires chaining along three pointers, not two.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Probably not. LC3 only exists in textbooks and moreover, people who volunteer here don't want to do your homework for you.

Give it an honest effort and we will help as you go along.

Salem commented: Damn fine answer! +18
Duoas 1,025 Postaholic Featured Poster

I'm not sure I understand what you are trying to do in your code (it is mixing siblings and children, which would be some kind of inversion...)

But if what you are trying to do is convert this:

+---+
    | 0 |--X
    +---+
      |
      V
    +---+   +---+   +---+
    | 1 |-->| 2 |-->| 3 |--X
    +---+   +---+   +---+
      |       |       |
      X       V       |
            +---+     |
            | 4 |--X  |
            +---+     |
              |       |
              X       V
                    +---+   +---+
                    | 5 |-->| 6 |--X
                    +---+   +---+
                      |       |
                      X       X

into this:

+---+
    | 0 |--X
    +---+
      |
      V
    +---+   +---+   +---+
    | 3 |-->| 2 |-->| 1 |--X
    +---+   +---+   +---+
      |       |       |
      |       V       V
      |     +---+
      |     | 4 |-X
      |     +---+
      |       |
      |       X
      V
    +---+   +---+
    | 6 |-->| 5 |--X
    +---+   +---+
      |       |
      X       X

Then consider how the general tree is organized. Each set of children is a singly-linked list. So all you have to do is iterate (or recurse) down through each child node and reverse the linked list of siblings.

It will help if you try to do it on paper. If you still get stuck there is a C code snippet for reversing a singly linked list where I responded with an iterative algorithm to do it (the original snippet is flawed).

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Why not use the STL? Is this schoolwork?

Either way, I still don't understand what you are trying to do with that function pointer. But the best place to get your head around it is to take a read through The Function Pointer Tutorials.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Whenever you hear people raging a lot about stuff like that you can almost always just ignore it.

The overhead of a virtual function call is so small that you have really got to be pushing the limits for it to make a difference.

Hmm... here's a link to the C++FAQ-Lite on virtual vs. static linkage:
http://www.parashift.com/c++-faq-lite/virtual-functions.html

Further, oo and generic programming are not orthogonal. They are simply different ways of handling different classes of problems. When the types of problem intersect, so do the methods to solve them.

For example, the STL I/O library uses both (polymorphic) inheritance and templates to provide us with such useful examples. But it isn't slow (when used properly).
http://www.artima.com/cppsource/scattered_io.html
(Most of the stuff you'll find where people are benchmarking I/O against C++ uses either outdated C++ libraries and/or stacks the test against C++ by using a lower class of I/O for comparison.)

So when people start expounding the virtues of <feature X> just nod your head and smile. Let them continue in their cultish delusions. And you can chuckle latter and feel perfectly justified using whichever technique best suits the problem.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I've seen far worse code... (and I've always gotten myself into a lot of trouble by 'complaining' about it --even when it was obvious that it was costing the company thousands of dollars in delays and workarounds).

It might be worth suggesting to the prof in charge that he consider a term (not now, but in the future ;) ) where a small group of students cull and clean the code, then identify simple refactorings and do them. Tell him it will be good experience for them (if they want it), and it will make it faster (probably true) and smaller (also probably true). If you can show that it breaks under common conditions you can also argue that the effort would increase the program's stability and security.

But for now, don't worry about it. You can't be responsible for the mess. You can only not contribute to it. If you get into making it better you'll just give yourself a headache and produce dissatisfied evaluations of your performance (because you spent your time doing something other than what you were supposed to do).

The best way to get used to the code is just to get a local copy of it and start trying to change things. After playing around with it for a short bit you'll have a pretty general idea of where things are and what you have to do to make modifications. Then you can check out the current copy and start adding/modifying …

Duoas 1,025 Postaholic Featured Poster

If you are in the USA then I'm pretty sure that your high school is required to accommodate you.

You might want to google around "greedy algorithm". Find the cheapest set of adjacent cars that holds at least as many people in your group.

Good luck!

Duoas 1,025 Postaholic Featured Poster

That macro invites death without warning.

If you want to swap something, #include <algorithm> and use std::swap().

@cecyl
Generic algorithms will work just fine, but if you know something about the probable distribution of your data then you can reduce sort time considerably.

If you know that you have a relatively small set of values, then you can reduce your sort time to constant or near-constant time by simply counting how many times each value appears, then writing them back out in order.

Good luck.

[edit] Man, get up to visit the bathroom and someone smart answers first...

Duoas 1,025 Postaholic Featured Poster

You need to turn the computer off and think about how to solve the problem before you confuse yourself with any more code. There is too much of it.

Here are some hints.

  • A 3x3 grid can be solved by placing the numbers 1 through 9 in it in any order.
    So long as there are no duplicates and the grid is completely filled, it is solved.
  • A specific row of the 3x3 grid can have up to six numbers excluded from it.
  • Likewise with a column.

Each one of those hints suggests a function to test a given number:

  • Is the number already in the 3x3 grid or not?
  • Is the number already in the 9x1 row or not?
  • Is the number already in the 1x9 column or not?

Don't if..else every possible combination. There are too many. Use your procedures in an algorithm to test numbers until you can find a valid match or potential match.

I suspect your teacher will expect you to use some recursion to solve this problem. (If you are just doing this on your own, then I suggest you use some recursion to solve this problem.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Hey, this game is cooler than dirt! :)

I am not sure what your requirements are -- are you supposed to make your program solve the puzzle? or are you just supposed to notice when the user has successfully solved the puzzle?

You have, BTW, a conflict in your data. Both '2' and the smiley are represented by '2'. Make the smiley an invalid number.

Then, if all you have to do is check to see if the user has succeeded in sorting the array, just count through the array with a loop, checking to see that the current index is larger than the last, ignoring the invalid value (which is the smiley).

If you have to solve the puzzle let me know and I (or someone) will give you some hints.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

It sounds like you are out of luck.

If you have been absent for valid reasons (medical emergency, death of immediate family member, etc) many Universities will require the professor to give you reasonable accommodations to make-up the work which you have missed.

I would add that your assignment is not very-well defined. You might want to ask your professor for some clarifications.

Good luck.

Duoas 1,025 Postaholic Featured Poster

If I had to do it in-place, I would have just reversed the entire string, then reversed each word in the string...

But you did a good job with your temp strings. Nice!

Duoas 1,025 Postaholic Featured Poster

Usually a TSR will override one of the user interrupts (like $60) so that you can communicate with it (and, for example, tell it to stop).

If I remember correctly, once you load a TSR you cannot unload it, but you can disconnect it by restoring the interrupt vectors to their original values.

The only other way to stop it is to reboot.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

A char is guaranteed to contain 8 bits, at least. (And unless you are playing with really old hardware, like ancient vaxen, a byte is also 8 bits.) But the compiler is not required to store individual chars in 8-bit entities.

So, yes, that's what I meant.

@zoner7
Don't modify cout. Just write a routine to do stuff for you.

I'm writing a Sudoku solver too... :)

The basic cell type can overload the shift operators for I/O:

struct cell_t
  {
  int value;
  // Whatever else I store in a single cell goes here
  };

std::istream& operator >> ( std::istream& ins, cell_t& cell )
  {
  // Get a cell. For example, if each cell is just one char, '1'..'9' and ' ':
  int c = ins.get();
  if (std::isdigit( c ) and (c != '0')) cell.value = c -'0';
  else                                  cell.value = -1;
  return ins;
  }

std::ostream& operator << ( std::ostream& outs, const cell_t& cell )
  {
  // This is the same as Ed's PrintValue() function,
  // with just a little extra error checking...
  if ((cell.value %10) == cell.value) outs << (char)(cell.value +'0');
  else                                outs << ' ';
  return outs;
  }

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The char datatype is not guaranteed to be stored in a single byte, either.


I would also like to expand somewhat on Ed's response. Typically you don't want to directly print your data, but you want to transform it when you read and write it.

That's what cin and cout do. If you give cout an int, it doesn't actually print an integer to the screen, it prints a string to the screen which represents the integer in a way that humans like to read.

The same is true for the cells of your Sudoku board. Use a function (like Ed's PrintValue()) to write the appropriate thing to screen.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Wrong forum. This is the C++ forum.

Binary I/O is straight-forward, but you need to be aware of certain caveats.

You never list the types of result and rest, but if they are different types then you are playing with fire.

You should also be aware of endianness issues and floating-point format issues, but for this example neither is a problem.

The last issue is fwrite() and fread() take a certain type of pointer.

Make sure you have all these conditions met:

const char* FileName = "myfile.bin";

FILE* OutputFile;
FILE* InputFile;

double OutputValue = 17.0;
double InputValue;

if ((OutputFile = fopen( FileName, "wb" )) == NULL) fooey();
fwrite( (const void*)&OutputValue, sizeof( OutputValue ), 1, OutputFile );
fclose( OutputFile );

if ((InputFile = fopen( FileName, "rb" )) == NULL) fooey();
fread( (void *)&InputValue, sizeof( InputValue ), 1, InputFile );
fclose( InputFile );

if (fabs( InputValue -OutputValue ) > 0.000001) fooey();

As a final note, make sure you use good variable names. Currently what you have is not very illuminating, and anything with a number tacked on the end is usually a bad idea.

A good way to think of it is that variables should be nouns (or noun phrases) and functions should be verbs (or verb phrases).

If this doesn't help, please post a complete example that demonstrates the problem. Good luck!