|
-
February 27th, 2012, 02:09 PM
#1
reverse the output from a pointer
Write a C program to read the list from the file
and store them in the arrays. Your program
should write the list of client’s account
number, client’s name and the client’s balance
to another file called “newdata.txt” in reversed
order and also display them on the screen.
An example of output dialog is shown below
Account Name Balance
800 Stacy 100.10
700 Michael 81.05
600 Dale 1005.30
500 Richard 214.89
400 Stone -45.23
300 White 0.00
200 John 345.67
100 Jones 24.50
--------
This is what I have done so far bellow here....But the only missing part is the reversed order of “newdata.txt”
contents. Please help! Been trying now for few days with no succes. =(
Regards,
Mark
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
FILE *ifpt,*ofpt;
int i;
double account;
double balance;
char name[25],s[60];
if((ifpt=fopen("client.txt","r")) == NULL)
{
printf("ERROR : File could not be opened\n");
exit(1);
}
if ((ofpt = fopen("newdata.txt", "w")) == NULL)
{
printf("ERROR : File could not be opened\n");
exit(1);
}
else
{
printf ("\nAccount\tName\t\tBalance\n");
fprintf (ofpt,"\nAccount\tName\t\tBalance\n");
}
for(i=0;i<8;i++)
{
fgets(s,59,ifpt);
sscanf(s,"%lf %s %lf", &account,&name,&balance);
sprintf(s,"%.2lf\t%s\t\t%0.2lf\n", account,name,balance);
puts(s);
fputs(s,ofpt);
}
fclose(ifpt);
fclose(ofpt);
getch();
system("pause");
return 0;
}
-
February 27th, 2012, 02:36 PM
#2
Re: reverse the output from a pointer
You'll probably want a struct to store each client's information, and as the assignment say, and array to store it all.
Also please read the Before You Post announcement about code tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|