the program woks fine for a single record but for multiple records it
isn't reading the entries properly...
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
void read(void);
void write(void);
void main(void)
{
clrscr();
write();
read();
getch();
}
void write()
{
FILE *ptr;
int id;
char name[20];
float sal;
ptr=fopen("new1.dat","w");
printf("Press control+z to terminate\nUr Id, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
while(!feof(stdin))
{
fprintf(ptr,"%d%s%f",id,name,sal);
printf("\nId, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
}
fclose(ptr);
}
void read(void)
{
FILE *ptr;
ptr=fopen("new1.dat","r");
int id2;
float sal2;
char name[20];
while(!feof(ptr))
{
fscanf(ptr,"%d%s%f",&id2,name,&sal2);
printf("%d %s %f\n",id2,name,sal2);
}
fclose(ptr);
} 11 2709 mo*********@gmail.com wrote:
#include<conio.h>
#include<graphics.h>
void main(void)
clrscr();
write();
read();
getch();
}
printf("Press control+z to terminate\nUr Id, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
while(!feof(stdin))
You're trolling, right? Please tell me you're trolling...
Richard rl*@hoekstra-uitgeverij.nl (Richard Bos) writes: mo*********@gmail.com wrote:
>#include<conio.h> #include<graphics.h>
>void main(void) clrscr(); write(); read(); getch(); } printf("Press control+z to terminate\nUr Id, Name, Salary:"); scanf("%d%s%f",&id,name,&sal); while(!feof(stdin))
You're trolling, right? Please tell me you're trolling...
Richard
is that a continuation of the other joke, or you're just carping on still?
<mo*********@gmail.comwrote in message
news:11*********************@q3g2000prf.googlegrou ps.com...
the program woks fine for a single record but for multiple records it
isn't reading the entries properly...
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
void read(void);
void write(void);
void main(void)
{
clrscr();
write();
read();
getch();
}
void write()
{
FILE *ptr;
int id;
char name[20];
float sal;
ptr=fopen("new1.dat","w");
printf("Press control+z to terminate\nUr Id, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
while(!feof(stdin))
{
fprintf(ptr,"%d%s%f",id,name,sal);
fprintf(ptr, "%d %s %f\n", id, name, sal);
You might imagine that scanf() is the mirror of printf(), but in fact it is
not. You have to tell printf() where to put the spaces.
>
printf("\nId, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
}
fclose(ptr);
}
void read(void)
{
FILE *ptr;
ptr=fopen("new1.dat","r");
int id2;
float sal2;
char name[20];
while(!feof(ptr))
{
fscanf(ptr,"%d%s%f",&id2,name,&sal2);
printf("%d %s %f\n",id2,name,sal2);
}
fclose(ptr);
}
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm
On 31 Aug, 07:40, mohdalib...@gmail.com wrote:
assuming you are being serious... Your program has multiple
problems.
the program woks fine for a single record but for multiple records it
isn't reading the entries properly...
- define "fine", "woks" and "isn't reading the entries properly"
- use of non-standard headers: <conio.hand <graphics.h>
- use of non-standard functions clrscr() and getch()
- bad layout
then read the comp.lang.c FAQ and fix:
- void main
- no return from main
- failure to check return value of fopen()
- no \n or fflush() after printf()
- incorrect use of feof()
- use of scanf() (it can be used but it is difficult)
- no check of return value from scanf()
- use of %s in scanf()
- use of float rather than double
and I probably missed something.
--
Nick Keighley
"They consider console off topic, i consider them morons."
(anon comp.lang.c)
On Aug 31, 1:10 pm, "Malcolm McLean" <regniz...@btinternet.comwrote:
<mohdalib...@gmail.comwrote in message
news:11*********************@q3g2000prf.googlegrou ps.com...
the program woks fine for a single record but for multiple records it
isn't reading the entries properly...
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
void read(void);
void write(void);
void main(void)
{
clrscr();
write();
read();
getch();
}
void write()
{
FILE *ptr;
int id;
char name[20];
float sal;
ptr=fopen("new1.dat","w");
printf("Press control+z to terminate\nUr Id, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
while(!feof(stdin))
{
fprintf(ptr,"%d%s%f",id,name,sal);
fprintf(ptr, "%d %s %f\n", id, name, sal);
You might imagine that scanf() is the mirror of printf(), but in fact it is
not. You have to tell printf() where to put the spaces.
printf("\nId, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
}
fclose(ptr);
}
void read(void)
{
FILE *ptr;
ptr=fopen("new1.dat","r");
int id2;
float sal2;
char name[20];
while(!feof(ptr))
{
fscanf(ptr,"%d%s%f",&id2,name,&sal2);
printf("%d %s %f\n",id2,name,sal2);
}
fclose(ptr);
}
--
Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
Thanks alot. You have solved my problem. Thanks.
"Richard Bos" <rl*@hoekstra-uitgeverij.nlwrote in message
news:46***************@news.xs4all.nl...
>while(!feof(stdin))
I thought that one was wrong as well. Actually it seems to be right. However
it probably indicates a poor understanding of feof().
--
Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm mo*********@gmail.com wrote:
>
the program woks fine for a single record but for multiple records
it isn't reading the entries properly...
#include<stdio.h>
#include<conio.h>
No such file in standard C
#include<stdlib.h>
#include<graphics.h>
No such file in standard C
void read(void);
void write(void);
void main(void)
main always returns an int.
Yhese have already made your code incomprehensible. Please remove
everything that is not standard (and thus OT) before posting it
again. Graphics are intrinsically system specific, and not dealt
with here in c.l.c.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com mo*********@gmail.com wrote:
You might imagine that scanf() is the mirror of printf(),
but in fact it is not.
The meaning of "%f" is also different for those two functions.
My two cents.
--
pete
On Aug 31, 11:40 am, mohdalib...@gmail.com wrote:
the program woks fine for a single record but for multiple records it
isn't reading the entries properly...
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
void read(void);
void write(void);
void main(void)
{
clrscr();
write();
read();
getch();}
void write()
{
FILE *ptr;
int id;
char name[20];
float sal;
ptr=fopen("new1.dat","w");
printf("Press control+z to terminate\nUr Id, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
while(!feof(stdin))
{
fprintf(ptr,"%d%s%f",id,name,sal);
printf("\nId, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
}
fclose(ptr);
}
void read(void)
{
FILE *ptr;
ptr=fopen("new1.dat","r");
int id2;
float sal2;
char name[20];
while(!feof(ptr))
{
fscanf(ptr,"%d%s%f",&id2,name,&sal2);
printf("%d %s %f\n",id2,name,sal2);
}
fclose(ptr);
}
BAD indentation!
<OT>
Run ``indent <c-file-name-ts4 -i4 -bli0'' on your code
</OT>
Regards,
Frodo B
this program seems writen in TC2.0,which was too old to meet C
standard.
scanf("%d%s%f",&id,name,&sal);
it can be more hale writen as scanf("%d,%s,%f",&id,name,&sal);
add a comma as separator.
while(!feof(stdin))
{
fprintf(ptr,"%d%s%f",id,name,sal);
printf("\nId, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
}
fclose(ptr);
and this follows can be:
if(NULL==ptr){/*out some message to user.*/exit(0);}
while(!feof(ptr))
{
fprintf(ptr,"%d,%s,%f",id,name,sal);
printf("\nId, Name, Salary:");
scanf("%d,%s,%f",&id,name,&sal); /*now you need add a comma
while typing.*/
}
fclose(ptr);
Good Luck
Kind Regards
Zeng Jun
UINDEX <Ui****@gmail.comwrites:
this program seems writen in TC2.0,which was too old to meet C
standard.
>scanf("%d%s%f",&id,name,&sal);
it can be more hale writen as scanf("%d,%s,%f",&id,name,&sal);
add a comma as separator.
I'm not sure what you mean by "more hale".
You can make that change if you like, but it changes the meaning of
the statement. A ',' character in a scanf format string requires a
literal ',' character in the input. Without the commas, the input
items may be separated just by whitespace.
An unqualified "%s" in a scanf format is a buffer overflow waiting to
happen.
>while(!feof(stdin))
{
fprintf(ptr,"%d%s%f",id,name,sal);
printf("\nId, Name, Salary:");
scanf("%d%s%f",&id,name,&sal);
} fclose(ptr);
and this follows can be:
if(NULL==ptr){/*out some message to user.*/exit(0);}
while(!feof(ptr))
{
fprintf(ptr,"%d,%s,%f",id,name,sal);
printf("\nId, Name, Salary:");
scanf("%d,%s,%f",&id,name,&sal); /*now you need add a comma
while typing.*/
}
fclose(ptr);
'ptr' appears to be an output file; why are you checking 'feof(ptr)'?
('ptr' is also a poor name for a FILE*.)
In any case, this is a misuse of feof().
See section 12 of the comp.lang.c FAQ, <http://www.c-faq.com/>.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Thomas Sourmail |
last post by:
Hi,
I hope I am missing something simple, but.. here is my problem:
I need my program to check the last column of a file, as in :
a b c d target ref
0 0 0 0 1 a
1 0 0 0 1.5 b
2 0 0 0 2 c
|
by: ArmedCoder |
last post by:
Hi, im just learning about multithreading for a program i am writin
that needs to read from multiple camreas attached to the computer a
the same time.
I know how to create threads and pass around...
|
by: Kay |
last post by:
1) If i want to read data from a txt file,
eg John; 23; a
Mary; 16; i
How can I read the above data stopping reading b4 each semi-colon and
save it in three different variables ?
2) If I...
|
by: Babak |
last post by:
Hi Everyone,
I've written a standard C code for a simple finite element analysis
in MSVC++ . When I save the file as a cpp file, it compiles and runs
perfectly, but when I save it as a c file,...
|
by: abhishekkarnik |
last post by:
Hi,
I am trying to read an exe file and print it out character by
character in hexadecimal format. The file goes something like this in
hexadecimal
0x4d 0x5a 0x90 0x00 0x03 .... so on
When I...
| |
by: Scott |
last post by:
Hi,
a problem with this following code is really bugging me.
tform = fopen(country, "r");
fseek(tform, 9L, SEEK_SET);
fgets(player2, 38, tform);
printf("Player Name (save): %s", player);...
|
by: rsk |
last post by:
Hi Friends,
I have written a code which suppose to read all the numbers from a hex
file,But to my surprise the code is skiping every alternate value.Don't
know why?
Can you please help me in...
|
by: neha_chhatre |
last post by:
i have a wierd problem...iam not able to understand wat is goin
wrong...i have written a code which reads the values form a text file
(it contains lot of values like time=1.147279,value=240.66 and...
|
by: Bert |
last post by:
Problem is documented at http://ace.delos.com/usacoprob2?a=deAhyErCKsK&S=gift1
Why doesn't this work?
/*
ID: albert.4
LANG: C
TASK: gift1
*/
|
by: kindrain |
last post by:
the code checks whether a.txt has exact the same lines, then write
different lines into b.txt
Here it is:
(before that ,you should creat a.txt)
----------------------
#include<stdio.h>...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |