Escolar Documentos
Profissional Documentos
Cultura Documentos
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main(void)
{
FILE *fptr; //file pointer
fptr = fopen("writeonly.txt","w"); //creates a file for writing.
//If file exists it will be deleted
printf("\nThe file was created");
fprintf(fptr,"%s","Hello");
printf("\nFile written to. Press any key to continue...");
getch();
}
********************************************************************************
************************************
Can find user file and can edit the user file
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
char fname[34];
char lname[25];
int main(void)
{
FILE *fptr; //file pointer
fptr = fopen("readwrite.txt","r+"); //opens a file for reading and writing
if(fptr == NULL)
printf("\nThe file was not found");
else
{
printf("\nThe file was found");
for(int c=0;c<3;c++)
{
printf("\nEnter First Name: ");
fflush(stdin);
gets(fname);
printf("\nEnter Last Name: ");
fflush(stdin);
gets(lname);
fprintf(fptr,"%s %s\n",fname,lname);
}
}
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MYSIZE 25
#define SIZE 3
typedef struct personal
{
char name[25];
char address[50];
int age;
}info;
void
void
void
void
openfile();
getinfo(info data[]);
printinfo(info data[]);
storeinfo(info data[]);
FILE *fptr;
int main(void)
{
info data[MYSIZE];
openfile();
getinfo(data);
printinfo(data);
storeinfo(data);
}
void openfile()
{
fptr = fopen("name.txt","a+"); //opens a file for reading only
if(fptr == NULL)
{
printf("\nThe
printf("\nPress
getch();
exit(1);
}
else
{
printf("\nThe
printf("\nPress
getch();
}
}
void getinfo(info data[MYSIZE])
{
for(int count=0;count<SIZE;count++)
{
clrscr();
printf("\nEnter name: ");
fflush(stdin);
gets(data[count].name);