Jishnu 160 Posting Pro

Hi all,

I was reading Vijaya Mukhi's The 'C' Odyssey UNIX - The Open-Boundless C (1st ed.). This is in reference to program 43 in the first chapter when file buffering is introduced.

#include <stdio.h>
int main() {
 FILE *fp;
 char buff[11]; 
 int pid;
 fp=fopen("baby1","r");
 pid=fork();
 if(!pid) {
  printf("initial file handle :: %d\n",ftell(fp));
  fread(buff,sizeof(buff),1,fp);
  buff[10]='\0';
  printf("child read :: %s\n",buff);
  printf("child file handle :: %d\n",ftell(fp));
 }
 else {
  wait((int *)0);
  printf("parent file handle :: %d\n",ftell(fp));
  fread(buff,sizeof(buff),1,fp);
  buff[10]='\0';
  printf("parent read :: %s\n",buff);
  printf("end file handle :: %d\n",ftell(fp));
 }
 return 0;
}

The contents of baby1 are:

abcdefghijklmnopqrstuvwxyz

As per the book, the output should be:

initial file handle :: 0
child read :: abcdefghij
child file handle :: 11
parent file handle :: 1024
parent read ::
end file handle :: 1024

The book explains this by saying that fread() reads 1024 characters (whatever the block size is) by default into a buffer. Hence the file pointer also moves by 1024 bytes which is reflected because the process is different.

I tried the same code on Solaris and RHEL and got interesting results.

Output on Solaris:

initial file handle :: 0
child read :: abcdefghij
child file handle :: 11
parent file handle :: 11
parent read :: lmnopqrstu
end file handle :: 22

This indicates that in Solaris, block size is the same as specified in the fread() arguments. There is no such thing called default block …

sree_ec commented: gud qn +1
Jishnu 160 Posting Pro

This may be relevant.

scream2ice commented: thnx +1
Jishnu 160 Posting Pro

lol.. What I really meant was that once you've achieved what you wanted to, its pretty difficult to maintain balance in one's life. I do believe that "An idle mind is a devil's workshop". After you've hit the jackpot, the only things that you'd be probably doing is social work, socializing with friends, etc. There would not be enough quality work to do and I might become idle (devil) sooner or later. Everyone might not succumb to such things, but I think I am not strong enough to be able to remain steadfast to that extent. Instead, it is good that I have a real goal in life, always.. Who knows, the road travelled may turn out to be more beautiful than the destination reached. I want to enjoy leading my life whatever it turns out to be.

Sulley's Boo commented: :P I like your signature +4
Jishnu 160 Posting Pro

Sorry about that Jishnu, sara_84 posted in two separate threads and a moderator has linked them. Now it looks like I asked her to post when she had already posted!

Understood.

Do not worry so far sara_84 did not reply to anything originaly posted in first or second post. I would say it is pass deadline.

Yes, I agree.

darkagn commented: You are always so nice to everyone! +1
Jishnu 160 Posting Pro

Hi nljavaingineur, I suggest you these things:

-Start a new thread for a new problem. It is related to this thread but you are using a different approach.
-Use code tags.
-Use proper alignment in code.

~s.o.s~ commented: Absolutely. +20
Jishnu 160 Posting Pro

Hello,

I wonder why am I getting negative reputation for starting threads in the geek's lounge.

Take a look over here.
http://www.daniweb.com/forums/member115698.html

When I put the cursor on the link to geek's lounge, the screen tip says, "A random forum for chat about anything... ". I did not say that Murphy's Laws explain everything. It is just a thread dedicated to Murphy's Laws, nothing else. I don't think there was any valid reason for iamthwee to do this.

Regards,
-Jishnu.

Note: iamthwee is refering to something in this http://www.daniweb.com/forums/thread102006.html thread and the negative reputation is given for some other post.

jbennet commented: if you care that much then heres a green square +22
jasimp commented: Just becasue you care so much about it -1
Rashakil Fol commented: Your avatar is adorable. +6
~s.o.s~ commented: You have to learn to ignore suckers. +20
Jishnu 160 Posting Pro

Originally discovered by technicians on crash tests at Cailfornia in 1949, Murphy's Laws spread quickly. They were spotted everywhere: buses always came in threes, desperately needed objects became invisible, etc...

Well, let us post them over here..

These are some of my favorite picks among the Murphy's Laws regarding software/technology. I've taken them from 'Why the toast always lands the butter side down' by Richard Robinson.

1) "If it's not in the computer, it does not exist."

2) "Whenever a system becomes completaly defined, some damn fool discovers something which either abolishes the system or expands it beyond recognition."

3) "Nothing ever gets built on schedule or within budget. Or, all is well that ends."

4) "If there is the possibility of several things going wrong, then the one that will cause the most damage will be the one to go wrong."

But why make you suffer more?! Should not make it lengthy for Murphy also says, "The longer you look at a page, the more the words don't get in." ;) ;)

Oops, I misspelt the thread title.

MidiMagic commented: Undoing the neg you got. +4
Jishnu 160 Posting Pro

sOperator gets its value using this statement.

sOperator = (String) arg;

If your problem is solved, mark this thread as solved by clicking on the link below the last post in this thread.

Jishnu 160 Posting Pro

This is your first post. But, the next time you post your code, please use code tags so that the users can view the code along with proper alignment.

if (isFixReg)
    sText2 = (String) arg;
else 
    sText2 = text.getText() + arg;
text.setText(sText2);
isFixReg = false;

This indicates that if isFixReg is true, then no other operand (argument) is needed to be displayed (For eg when memory/clear buttons or operators are selected). If isFixReg is false, then another argument is to be added to the text being displayed.

For eg if you press 21, then when you press 2 then isFixReg is true and afterwards when you press 1 then isFixReg is false because it has to display the previous argument (which was 2) also to display '21' and not only '1'. I hope I'm clear.

Looks like darkagn and I replied at about the same time. I hadn't refreshed my page while typing my reply.

darkagn commented: nice explanation :) +1
Jishnu 160 Posting Pro

You are surely not going to get anyone to write the entire code for you. You know how to do the task. Separate it into several small manageable modules. Write the algorithm in a logical order. Refering to each step in the algorithm, write the corresponding C language statements. After you've written the entire code, compile/run it. Try to debug the errors if any. If you are unable to do so, you will definitely get help from this forum. I don't see in what other way I can help you. Please mention if this is not what you were looking for. In that case you need to be more specific with the kind of help you want.

Ancient Dragon commented: Great advice :) +19