Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

Make money selling software. Check this out here

Hosted clickbank mall. Check this out here




   Misc

   Amazon

   Links

    


Open, read and write to a file
 

 

Description

This example reads from a file , acts on the data in the file and then writes out to another file depending on the data.

Code

/*
This example shows opening a file , reading the data
acting on the data in the file and the saving this to
another file
*/
#include <stdio.h>

int main()
{
float sales , commission;
FILE *fin, *fout;
fin = fopen("d:\\sales.dat","r");
fout = fopen("d:\\commission.dat","w");
while (fscanf(fin,"%f",&sales) != EOF)
{
fprintf(fout,"Your sales for the year were %8.2f \n",sales);
if(sales < 30000)
commission = sales / 100 * 5;
else
commission = sales / 100 * 10;
fprintf(fout,"Your commission is %8.2f",commission);
}
return 0;
}

Information

tested using LCC Win 32

 

 

 

 

Download

readwritefile.txt


 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
Mozilla or Internet explorer(PHP)
Currency convertor(PHP)
File attributes(C)
date and time in status bar(Javascript)
Count words in a string(VB.net)
Count words in a sentence(ASP)
read a character using cin(C++)
GD email address(PHP)

    




Copyright © 2003 by programmershelp.co.uk