#include <stdio.h>
#include <conio.h>
int main() {
int arr[3] = {4,5,6};
FILE *fp ;
fp = fopen("C:\\a.txt","rt");
if(fp)
{
printf("Read\n");
for(int i=0;i<3&& arr[i] != EOF;i++)
{
arr[i] = fgetc(fp);
}
}
else
{
fp = fopen("c:\\a.txt","wt");
printf("Save\n");
for(int i=0;i<3;i++)
{
fputc(arr[i],fp);
}
}
for(int i =0;i<3;i++) {
printf("%3d",arr[i]);
}
getch();
}
fp = fopen("C:\\prog.dat","rt");
if(fp)
{
while (ex[i++].kala[i++]!= EOF)
{
// inja ro chy benvisam
ex[i].vazn= fgetc(fp);
//
i++;
}
}
#include <iostream.h>
#include <fstream.h> // for file_stream
#include <stdlib.h> // for exit(1)
void main()
{
int a[4]={2,43,54,4};
char *b[4]={"abc","efg","ert","ghi"};
ofstream myfile( "C:\\a.txt", ios::out );
if ( !myfile )
{
cerr << "File could not be opened" << endl;
exit( 1 );
}
for (int counter=0 ; counter<4 ; counter++ )
myfile << a[counter] << ' ' << b[counter] << endl;
}
#include <iostream.h>
#include <fstream.h> // for file_stream
#include <stdlib.h> // for exit(1)
void main()
{
int a[4]={11,11,11,11};
char *b[4]={"ddd","ddd","ddd","ddd"};
ifstream myfile( "c:\\a.txt", ios::in );
if ( !myfile )
{
cerr << "File could not be opened" << endl;
exit( 1 );
}
// khaandan az file
for (int counter=0 ; counter<4 ; counter++ )
myfile >>a[counter] >> b[counter];
// chaap dar safheh
for (int counter2=0 ; counter2<4 ; counter2++ )
cout<<a[counter2]<<" "<<b[counter2]<<endl;
}
#include <iostream.h>
#include <fstream.h> // for file_stream
#include <stdlib.h> // for exit(1)
void main()
{
char *kalameh=" ";
ifstream myfile1( "c:\\text.txt", ios::in );
ofstream myfile2( "c:\\text2.txt", ios::out );
if ( !myfile1 || !myfile2)
{
cerr << "File 1 or 2 could not be opened" << endl;
exit( 1 );
}
for(int counter=0 ; counter<150 ;counter++ )
{
myfile1 >>kalameh ; // khandan az file 1
// .............
// .............
// .............
cout<<"kalameh= "<<kalameh<<endl;
// .............
// .............
// .............
myfile2 << kalameh << endl; // neveshtan dar file 2
}
}
#include <iostream.h>
#include <fstream.h> // for file_stream
#include <stdlib.h> // for exit(1)
[color=red]#include <string.h>[/color]
void main()
{
char *kalameh=" ";
[color=red]int barasi=97;[/color]
ifstream myfile1( "c:\\text.txt", ios::in );
ofstream myfile2( "c:\\text2.txt", ios::out );
if ( !myfile1 || !myfile2)
{
cerr << "File 1 or 2 could not be opened" << endl;
exit( 1 );
}
while ([color=red]barasi[/color])
{
myfile1 >>kalameh ; // khandan az file 1
[color=red]barasi=strcmp(kalameh ,"") ;[/color]
// .............
// .............
// .............
cout<<"kalameh= "<<kalameh<<endl;
// .............
// .............
// .............
myfile2 << kalameh << endl; // neveshtan dar file 2
}
}
#include <iostream.h>
#include <fstream.h> // for file_stream
#include <stdlib.h> // for exit(1)
#include <string.h>
void main()
{
char *kalameh=" ";
int barasi=97;
ifstream myfile1( "c:\\[color=red]myrtf.rtf[/color]", ios::in );
ofstream myfile2( "c:\\text2.txt", ios::out );
if ( !myfile1 || !myfile2)
{
cerr << "File 1 or 2 could not be opened" << endl;
exit( 1 );
}
while (barasi)
{
myfile1 >>kalameh ; // khandan az file 1
barasi=strcmp(kalameh ,"") ;
// .............
// .............
// .............
cout<<"kalameh= "<<kalameh<<endl;
// .............
// .............
// .............
myfile2 << kalameh << endl; // neveshtan dar file 2
}
}
char * c……;
char c….;
#include <iostream.h>
#include <fstream.h> // for file_stream
#include <stdlib.h> // for exit(1)
void main()
{
[color=red]char c[/color]='k';
ifstream myfile1( "c:\\text.txt", ios::in );
ofstream myfile2( "c:\\text2.txt", ios::out );
if ( !myfile1 || !myfile2)
{
cerr << "File 1 or 2 could not be opened" << endl;
exit( 1 );
}
while ( [color=red] c != '\0'[/color] )
{
[color=red] c='\0';[/color]
myfile1 >>c ; // khandan az file 1
// .............
// .............
// .............
cout<<" c= " <<c<<" (int)c= "<<(int)c<<endl;
// .............
// .............
// .............
myfile2 << c << endl; // neveshtan dar file 2
}
}
#include <stdio.h>
#include <cstring.h>
#include <conio.h>
#include <iostream.h>
#define size 100
struct kala{
char name[50];
int vazn,gh;
} ex [size] ;
void jadid (int z);
void jostejo(char name[20]);
void load ();
main()
{
char price,na[20];
int i,j,z=0;
FILE *f;
load();
vorodi:
clrscr();
cout <<"New Recorde [1] :::"<<" [ search [2] ]"<<endl;
cin >> j;
switch (j){
case 1 :
z++;
jadid(z);
goto vorodi;
case 2 :
clrscr();
cout <<"name of material : ";
cin >> na;
jostejo(na);
default:
goto vorodi;
}
return(0);
}
void jadid (int z){
register int i=0;
char ch,num[20];
FILE *f;
f=fopen("kala.dat","wt");
clrscr();
while (1)
{
cout <<"material: " ;
cin >> ex[i].name;
cout <<"w: " ;
cin >> num ;
ex[i].vazn=atoi(num);
cout <<"price : " ;
cin >> num;
ex[i].gh=atoi(num);
if(*ex[i].name)
fwrite(&ex[i],sizeof(struct kala),1,f);
i++;
if ((ch=getche())== '+')
break;
}
}
void jostejo(char name[20]){
char ch;
register int i=0;
register int y=0;
load();
clrscr();
while(i<size)
{
if (strcmp(ex[i].name,name)==0)
{
cout<<ex[i].vazn<<" "<<ex[i].gh ;
y=1;
break;
}
else
y=0;
i++;
}
if (y==0)
cout << "can not find material " ;
getch();
}
void load (){
FILE *f;
register int i;
f=fopen("kala.dat","rt");
if(f==NULL)
{
cout <<"\n cannot open file";
cout <<"\n press a key... ";
getch ();
return ;
}
else
{
while (feof(f))
fread(&ex[i],sizeof(struct kala),1,f);
}
}