Hi,
I need to know what should be in the data.txt file after the program in the attached file will run.
What the fucntion does ? and why I see in the data.txt file two smiley (one white & one black)
Thanks,
E
Hi,
I need to know what should be in the data.txt file after the program in the attached file will run.
What the fucntion does ? and why I see in the data.txt file two smiley (one white & one black)
Thanks,
E
You opened a file, but wrote nothing to it:
If you want something else written to the file, put it in front of the return statement. I'm guessing that what you see are what makes up the file headerreturn 1;
fwrite(p,sizeof(int),n+1,fp);
Your function func is attempting to read a file in binary format. In order to do that you need to open your dat file in the right mode.
There are things not to like about your program. For one, func's body is not complete.
I think you know that nothing after a return statement will be executed.Code:while (scanf("%d",&x)!=EOF){ func(fp,x); } return 1; fwrite(p,sizeof(int),n+1,fp);
Also, scanf works on files opened in text mode, not binary mode. Are you sure you need to use fread? Until you make up your mind how to open your file and read it, it won't matter what you fix.
Let's say that the input will be the number 4 8 10 1 4, so what should be in the data.txt file.
The input is text and the file data.txt will be binary, even that is .txt
In other words what does the function ?
If you want to know what is the output, then run the program. If you want to know what the function does, then volunteer your answer first. Who wrote that function, anyway?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Never mind...misread what you were trying to do.
Last edited by rags_to_riches; 06-23-2008 at 12:05 PM. Reason: Oops
And she didn't tell you what it does? Could that be because she wants YOU to determine what it does?
You don't need to know English; you need to know C. Sit down with a piece of paper, decide what your input is going to be (which you already seem to have done), and step through it line-by-line and watch what happens.
Granted, nothing will get written to the file, as mentioned earlier, since the return 1 comes first. I don't feel like looking it up right this minute, but calling fread on a file pointer opened with "w+" worries me too. But you can pretend all those are fixed and watch what happens.