Jishnu 160 Posting Pro

Thanks sree_ec. This is the code I experimented on. It is derived from the code posted there.

#include<stdio.h>
#include<unistd.h>
int main()
{
FILE *fp;
char buff[11];
int pid, i;
fp=fopen("vivek","w+");
for(i=0;i<8192;i++)
    fprintf(fp,"A");
for(i=0;i<8192;i++)
    fprintf(fp,"B");
for(i=0;i<8192;i++)
    fprintf(fp,"C");
for(i=0;i<8192;i++)
    fprintf(fp,"D");
fclose(fp);
fopen("vivek","r");
printf("M0 ftell-> %ld lseek-> %ld buff-> %s\n",ftell(fp),lseek(fileno(fp),01, SEEK_CUR), buff);
pid=fork();
if(pid==0)
{
printf("C1 ftell-> %ld lseek-> %ld buff-> %s\n",ftell(fp),lseek(fileno(fp),01, SEEK_CUR),buff);
fread(buff,sizeof(buff),1,fp);
buff[10]='\0';
printf("C2 ftell-> %ld lseek-> %ld buff-> %s\n",ftell(fp),lseek(fileno(fp),01, SEEK_CUR),buff);
sleep(2);
printf("C5 ftell-> %ld lseek-> %ld buff-> %s\n",ftell(fp),lseek(fileno(fp),01, SEEK_CUR),buff);
fread(buff, sizeof(buff),1,fp);
buff[10]='\0';
printf("C6 ftell-> %ld lseek-> %ld buff-> %s\n",ftell(fp),lseek(fileno(fp),01, SEEK_CUR), buff);
_exit(0);
}
else
{
sleep(1);
printf("P3 ftell-> %ld lseek-> %ld buff-> %s\n",ftell(fp),lseek(fileno(fp),01, SEEK_CUR),buff);
fread(buff,sizeof(buff),1,fp);
buff[10]='\0';
printf("P4 ftell-> %ld lseek-> %ld buff-> %s\n",ftell(fp),lseek(fileno(fp),01, SEEK_CUR),buff);
sleep(3);
printf("P7 ftell-> %ld lseek-> %ld buff-> %s\n",ftell(fp),lseek(fileno(fp),01, SEEK_CUR),buff);
fread(buff,sizeof(buff),1,fp);
buff[10]='\0';
printf("P8 ftell-> %ld lseek-> %ld buff-> %s\n",ftell(fp),lseek(fileno(fp),01, SEEK_CUR),buff);
_exit(0);
}
}

The output is:

M0 ftell-> 0 lseek-> 1 buff->
C1 ftell-> 1 lseek-> 2 buff->
C2 ftell-> 13 lseek-> 8195 buff-> AAAAAAAAAA
P3 ftell-> 8195 lseek-> 8196 buff->
P4 ftell-> 8207 lseek-> 16389 buff-> BBBBBBBBBB
C5 ftell-> 8208 lseek-> 16390 buff-> AAAAAAAAAA
C6 ftell-> 8220 lseek-> 16391 buff-> AAAAAAAAAA
P7 ftell-> 8210 lseek-> 16392 buff-> BBBBBBBBBB
P8 ftell-> 8222 lseek-> 16393 buff-> BBBBBBBBBB

This output helped me understand the behaviors satisfactorily.

Thanks all for the help. I highly appreciate it.

Still I would like to state an interesting conclusion

The high-level call fread() is buffered. By default, it reads a block of data …

Jishnu 160 Posting Pro

Q3: The author may be wrong. Wouldn't be the first time wrong info was printed in a book.

Ok. Lets leave Q-3 aside for the time being.

http://www.linuxquestions.org/questions/programming-9/fork-and-file-buffering-791825/

Before trying to answer all these, i would suggest you to read this. thanks to google for getting me this.

Now you might be in a position to ans all these qns by yourself...
and for 3rd question, Guess blocksize as 1024 for the author..

So as far as it turns out to be , in diff os's the buffering parameter is also varying.So in the case we use vfork() and assume that it shares same fle pointer structure
, we can still come to a logical conclusion.

So finally it seems, fork() [using diff memory space] and buffering parameter differences in OS's makes this problem.

Let me get back to you after reading your link and doing some further experiments.

Jishnu 160 Posting Pro

we need to do a clean up before child terminates. So add an exit(0); or _exit(0); before the process terminates. This should solve the problem

Thanks sree_ec. I added exit(0) for child (the vfork case) and it gave the same output as Solaris gives for fork().

The point is that even though parent and child have distinct FILE objects, both of them refer to the same file obect in the kernel. The parent's ftell() obtains the read pointer from this shared object, which is of course affected by child's read().

This is understood. The question arises when only 10 characters are read by the child and fp is pointing to the EOF when parent resumes. It should point to 11 only.

Now, let's see what we have concluded until now. Earlier one question was that why does a library call fread() work differently across different OS. It looks like the different outputs across different OS is a consequence of using fork() system call. So that is okay.

Let me list down the questions that remain:

Q-1) Why does fp point to EOF in case of RHEL and Mac after the parent resumes when only 10 characters are read in the child process?

Q-2) How is the value returned by ftell(fp) after the parent resumes affected by the fact that fork() is defined differently in different OS?

Q-3) Why is the author of the book expecting the fp to point to 1024 (or the block …

Jishnu 160 Posting Pro

This is the output on Solaris in the case of vfork()

initial file handle :: 0
child read :: abcdefghij
child file handle :: 11
parent file handle :: -1
Segmentation Fault (core dumped)

I will add a detailed post later.

Jishnu 160 Posting Pro

~$ ./test
initial file handle :: 0
child read :: abcdefghij
child file handle :: 11
parent file handle :: 28
parent read ::
end file handle :: 28
~$

See, that is similar to what I got on RHEL! It is showing 28 instead of 26, maybe due to some leading/trailing whitespaces. I am also waiting in case anybody comes up with some sort of explanation :)

The book is good, introduces unix as a multitasking multiuser OS, covers file handling, and exhaustively covers IPC, some system calls and curses.

Jishnu 160 Posting Pro

The operating system may read into memory any amount of the file it wants to (buffering), but the file pointer only moves to the location requested in the program. There is little, or no, connection between the operating system's buffer size and the location of the file pointer.

That is what I thought. It seems to be quite logical too. I got my doubts after running it on RHEL. And from that I was surprised to see library calls behaving differently across two different OS.

There was no error in running the code on RHEL. Maybe someone with easy access to RHEL can give it a shot?

Thanks.

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

batman -> heroes

Jishnu 160 Posting Pro

apples and chocolates

Jishnu 160 Posting Pro

2008 is the current year.

Jishnu 160 Posting Pro

blamers

Jishnu 160 Posting Pro

what is the logic i need to use so that on cliking Commandbutton in form2 i should get the customername in combobox(form1)

No 'logic' as such. You need to be well-conversant with the basic properties and methods of the listbox and combobox controls.

Jishnu 160 Posting Pro

To make the OS independent of hardware is in the hands of the programmers.

More true would be, "To make the OS compatible with maximum amount of uPs that are being used in the target market."

Jishnu 160 Posting Pro

Using Timer may be the good solution.

Agreed. That is more practicable for such long delays.

Jishnu 160 Posting Pro

The 90/10 rule usually applies.

90% of the time, it's some noob with nothing better to contribute than "yeah, me too, plzsndmetehcode" or other barely literate lameness.

Exactly.

Jishnu 160 Posting Pro

Sorry for stealing others thread.

Then don't do it in the first place.

Jishnu 160 Posting Pro

Isn't your question vague? Avoid forcing people who want to help you to assume anything.

Jishnu 160 Posting Pro

Well, I've used it this way. No other ideas.

Jishnu 160 Posting Pro

Post it in this forum if you're in search of project partners.

Jishnu 160 Posting Pro

And u should know what is ur target hardware(uProccessor). before proceeding.

Exactly. Work out those details before commencing this big a task.

Jishnu 160 Posting Pro

yeah, i really wish threads that have been inactive for more than 90 days would be automatically locked.

I'd reported this problem earlier in DaniWeb Community Feedback, but somehow, things didn't work out. Some problem regarding the workload that means for the mods or the work required for automating the 'lock' feature.

Jishnu 160 Posting Pro

Stemming is another algorithm I found to be of interest for similiar purposes.

Jishnu 160 Posting Pro

My post shows you one way to introduce those 2-minute delays that you want.

Jishnu 160 Posting Pro
Jishnu 160 Posting Pro

i m creating a new project of vb to access conncetivity in 5 PC small LAN.
I don't Know What is the code,connection string use in project. And I am biginar for that type of programming.

There might be ready-made API's out there.

I want to store data in server, access database tables.

For dealing with MS Access through VB, use ADODB.

Jishnu 160 Posting Pro

It is connected with its main unit with 15 pin serial port like thing

Your being more specific will help us help you more.

Jishnu 160 Posting Pro

Write this code in the declaration section:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Then suppose you want a delay of 2 minutes, then convert it into milliseconds, i.e. 120000.

Sleep(120000)
Jishnu 160 Posting Pro

Can anybody help me in filling an Access database table in one field
from a serial port using VB 6.0.Data coming from the serial port can be seen in the VB text box line by line.I want to store every line under a field and can manipulate.How can i use MSComm command ? Can this command work -for example 'Data2.RecordSource = Text1.Text'

Eh?! What's the point repeating the words of the OP?

MSComm32 control can be used for serial port communication and for database handling (MS Access), you may use ADODB.

Jishnu 160 Posting Pro

And even if it did, it is written in C++, not C

Oh, I didn't realize that earlier. This is what happens when you go on switching between the C and C++ forums.

Jishnu 160 Posting Pro

Any tips welcome! Even if it doesnt solve this. =D

Codes along with relevant comments always get more help!

Jishnu 160 Posting Pro

http://www.codeproject.com/KB/GDI/kanjifont.aspx

Though, I'm not sure whether it will help you in the case of Hindi.

Jishnu 160 Posting Pro

Okay. Post the entire code if possible. The root cause of the problem may lie somewhere else rather than in the code you've given.

Jishnu 160 Posting Pro

If you're free to choose the mode of communication between the computers QUOTE]

Thanks for answering - much appreciated. It's reassuring to hear you had no problem even with Access 2003. My other concern is that of implementing this on a network, albeit a small one (3/4 users). Can you suggest any good sources of information on this (bearing in mind my novice status) - books, online tutorials?
Thanks.

For ready-made API's use google. Or if you like, you can establish PC to PC communication links via the serial port using the the MSComm32 control.

Jishnu 160 Posting Pro

Are you sure you've declared those variables as public?

Jishnu 160 Posting Pro

Tanenbaum would be a good idea.

Jishnu 160 Posting Pro

I've read of the version issues (having to convert to Access 97) but I downloaded service pack 6 and I have no problem accessing tables on a test Access 2000 database on my work pc.

It worked even with Access 2003 on my PC.

The business I work for want all their paper data stored in Access 2000, and to be accessible through a small network - server, 3/4 PCs running XP.

The main question is: Is there any reason not to use VB6 for this?

If you're free to choose the mode of communication between the computers, you can implement it using VB6. You have ready-made controls for serial data communicaton; and as far as the 'version issue' is concerned, it's not an issue at all!

Jishnu 160 Posting Pro

This may be relevant.

scream2ice commented: thnx +1
Jishnu 160 Posting Pro
Jishnu 160 Posting Pro

Nope the problem just states to print charts showing the conversions. - Print the outputs in a neat tabular format that minimizes the number of lines of output while remaining readable.

Sorry, but I'm not able to understand the format of the output you want from the program. I'll be able to help if you describe in a bit detail.

Jishnu 160 Posting Pro

LOL...

Jishnu 160 Posting Pro

Do you mean a bar chart? Then scale those values by a suitable factor and then display the results. For e.g. for Celsius to Fahrenheit, take 0 to 100 on X-axis, and 32 to 212 on Y-axis. Scale the values so that the chart fits into the console and show the variations. Note: You're expected to display the scale while plotting such bar charts. i.e. 1 '*' = x degree Celsius and so on (where you're using columns of the character '*' as the vertical bars).

Jishnu 160 Posting Pro

Just create your normal application and add it to the scheduled tasks. You don't need to worry much about (regarding the code) the scheduling part.

Jishnu 160 Posting Pro

Inside the if blocks that you've commented, wait for a character to be pressed by the user. That would print all the results on the console, and at the same time, the user will be able to view them page-wise.

Jishnu 160 Posting Pro

I have a little problem with two panels that are on top of eachother with the exact same Size.
What I am trying to do is with 2 buttons to choose wich panel that will be visible and not visible.
So what should happen is that only one panel can be seen at a time.

Instead of keeping two buttons for this task, why not use two radio buttons? This would be more appropriate as you want only one of the panels to be visible at a time.

Jishnu 160 Posting Pro

i am proficiant in C++ and was wondering if it is possible to create a mmorpg using just that?

Yes.

also would you b able 2 use dark gdk or visual c++?

Yes.

a third point is which pecific parts, would i use which language for?

Couldn't understand this question.

Jishnu 160 Posting Pro

No problems regarding the compiler, then. I'm unaware about the details of this problem. Yeah, it is a memory problem; atleast. But I'd still suggest that you learn dynamic memory allocation... That'd be better for the magnitude of array elements you're dealing with.

Jishnu 160 Posting Pro

Do that if it doesn't hamper the various functions the header file is meant to serve. I'm not sure how it may affect the operation.

Jishnu 160 Posting Pro

What compiler are you using? If you're using one of those old compilers, make the memory model large.

Dynamic memory allocation would be a better solution.

Jishnu 160 Posting Pro

i was wondering if it was possible to make a mmorpg using C++, with out being to proficiant in javascript and html and either what software i would need or where to start.X

You need to start with C++. Be specfic with your questions. MMORPG is too vague.

Jishnu 160 Posting Pro

Does this appear to be a homework help site? Show your efforts and specify your problems in order to get effective help.