Unix questions - Probelm:

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > September 2005 > Probelm:





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Probelm:
hirenshah.05@gmail.com

2005-09-27, 5:55 pm

I am trying to a program which takes the data from user and write in
file. I have written the code below. but when i am displaying data from
file; only first data is correct; others are random. i think there is
problem while writing in file.



struct st
{
char ch[60];
int n;
};

int main()
{
st s;
printf("enter");
scanf("%s",s.ch);
printf("enter no.");
scanf("%d",&s.n);
adddata(&s);
}



add data(st *x)
{
int fd;
fd=open("records",O_CREAT|O_RDWR,0644);
close(fd);
fd=open(path,O_CREAT|O_APPEND|O_RDWR);
fdw=write(fd,x,sizeof(s));
close(fd);
}


Then i have created another function to read from file "records" and
display all data entered.

But when i am adding data , Only first data enter is correct ; rest of
the data are random. I am not getting where is problem.

John Gordon

2005-09-27, 5:55 pm

In <1127835086.786612.77690@g47g2000cwa.googlegroups.com> "hirenshah.05@gmail.com" <hirenshah.05@gmail.com> writes:

> I am trying to a program which takes the data from user and write in
> file. I have written the code below. but when i am displaying data from
> file; only first data is correct; others are random. i think there is
> problem while writing in file.


Your example has several syntax errors. Please post the real program.
Also post the program which displays the data.

--
John Gordon "It's certainly uncontaminated by cheese."
gordon@panix.com

Bit Twister

2005-09-27, 5:55 pm

On Tue, 27 Sep 2005 16:00:48 +0000 (UTC), John Gordon wrote:
> In <1127835086.786612.77690@g47g2000cwa.googlegroups.com> "hirenshah.05@gmail.com" <hirenshah.05@gmail.com> writes:
>
>
> Your example has several syntax errors. Please post the real program.


After you fix all the compile errors. Please.

> Also post the program which displays the data.


Barry Margolin

2005-09-27, 8:50 pm

In article <slrndjitb7.d82.BitTwister@wb.home.invalid>,
Bit Twister <BitTwister@mouse-potato.com> wrote:
[vbcol=seagreen]
> On Tue, 27 Sep 2005 16:00:48 +0000 (UTC), John Gordon wrote:
>
> After you fix all the compile errors. Please.
>

He already posted to comp.unix.programmer, and there have been several
responses there. Please ignore him if he continues to multi-post here.

I've copied this in email to the OP, since he ignored my posted
admonition against multi-posting yesterday.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com