Results 1 to 2 of 2
I was writing a program that had a whole bunch of data transfer, when I realized that I have almost no idea what goes on behind the scenes of such ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-23-2005 #1Just Joined!
- Join Date
- Oct 2005
- Posts
- 1
Data Transfer Question
I was writing a program that had a whole bunch of data transfer, when I realized that I have almost no idea what goes on behind the scenes of such an endevor. I am not the type of person who likes to have things happen "magically" so I was wondering if anyone knew how it worked. I have already scoured the web but have not found much of anything on this topic. But here is what I am talking about.
For example;
When this program begins to execute, the character 'a' will be placed in memory by the C run-time environment. This character will then be sent to a file "output.txt".Code:#include <stdio.h> main () { char c ; FILE *fp; if (( fp = fopen ("output.txt", "w")) == NULL ) printf ("\n Cannot open the file: output.txt\n"); else { c = 'a'; fputc ( c, fp); fclose (fp); } }
I want to know how 'a' is bound to a particular place in memory. I also want to know what happens to get this character to a particular physical record on a physical disk unit.
I know this is kind of an advanced question, but I would love it if someone knew the answer, or if someone could point me in the right direction (because my searches didn't bring up anything close to what I wanted).
- 10-23-2005 #2
Re: Data Transfer Question
1. 1 byte of memory is automagically allocated. It can hold one character ( integers -127 through 127 ) and is referenced by the label c
Originally Posted by maiios
2. A pointer to a FILE structure is created, and given the name 'fp'
3. Several things happen:
First, output.txt is open()'d. If doesn't exist, it is created. If it already exists, then it is next truncated.
Then, fp is set to point to that memory
4. c now contains the integer 0x61 ( decimal 97, which is the ASCII code for the letter 'a' )
5. c, which contains the integer 0x61 ( decimal 97, ASCII a ), is copied to the file stream ( output.txt ) pointed to by the FILE pointer fp
6. The FILE descriptor fp is closed
-lakerdonald


Reply With Quote
