RUPAK SEARCH ENGINE

Custom Search

Examples of files in turbq C

Examples
#include
main()
{
FILE *buffer;
char text[20];
clrscr();
printf("Enter you name to store in data file: ");
scanf("%s",text);
buffer=fopen("txt.dat","w");
fprintf(buffer,text);
fclose(buffer);
/*see the text from dos */
}
/*---------------------------------------------------------------------------*/
#include
struct record
{
char name[20];
char address[20];
} student[5];

main()
{
FILE *buffer;
char fname[20];
int num,i;
clrscr();
printf("Enter the file name: ");
scanf("%s",fname);
buffer=fopen(fname,"a");
printf("How many students? ");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
printf("Name: ");
scanf("%s",student[i].name);
printf("Address: ");
scanf("%s",student[i].address);
fprintf(buffer,student[i].name);
fprintf(buffer,student[i].address);
fprintf(buffer,"\n");
}
fclose(buffer);
}


Examples
#include
main()
{
FILE *buffer;
char text[20];
clrscr();
printf("Enter you name to store in data file: ");
scanf("%s",text);
buffer=fopen("txt.dat","w");
fprintf(buffer,text);
fclose(buffer);
/*see the text from dos */
}
/*---------------------------------------------------------------------------*/
#include
struct record
{
char name[20];
char address[20];
} student[5];

main()
{
FILE *buffer;
char fname[20];
int num,i;
clrscr();
printf("Enter the file name: ");
scanf("%s",fname);
buffer=fopen(fname,"a");
printf("How many students? ");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
printf("Name: ");
scanf("%s",student[i].name);
printf("Address: ");
scanf("%s",student[i].address);
fprintf(buffer,student[i].name);
fprintf(buffer,student[i].address);
fprintf(buffer,"\n");
}
fclose(buffer);
}



#include
#define finished 0
main()
{
FILE *buffer;
char filename[10];
char text[20];
clrscr();
printf("Enter existing data file name to read: ");
scanf("%s",filename);
if((buffer=fopen(filename,"r"))==finished)
printf("Wrong file name! ");
else
{
fscanf(buffer,"%s",text);
printf("%s",text);
}
getch();
fclose(buffer);
}


#include
#define finished 0
main()
{
FILE *buffer;
char filename[10];
char text[20];
clrscr();
printf("Enter existing data file name to read: ");
scanf("%s",filename);
if((buffer=fopen(filename,"r"))==finished)
printf("Wrong file name! ");
else
{
fscanf(buffer,"%s",text);
printf("%s",text);
}
getch();
fclose(buffer);
}

No comments:

Post a Comment