in c++ create a program that does the following: Create a program that works wit
ID: 3694451 • Letter: I
Question
in c++ create a program that does the following:
Create a program that works with external files. Create functions to perform the following actions: file creation/write, file append and file read. Objective: Create use and pass filestreams that input/output data to and from external files. Lab Procedure: 1.Write the function to create n lines of a new, user named output file. 2.Write the function to append n lines to an existing file. 3.Write the function to read a user selected file and display it on the console.Explanation / Answer
1.CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char *sfname;
int n,i;
clrscr();
printf("Enter the file name:-");
gets(sfname);
fp=fopen(sfname,"w");
for(i=1;i<=10;i++)
{
printf("enter the number - ");
scanf("%d",&n);
putw(n,fp);
}
fclose(fp);
getch();
}
3.CODE
#include <stdio.h>
#include <conio.h>
#include <process.h>
int main()
{
FILE *fp;
char ch;
clrscr();
fp=fopen("D:\test.txt","r");
if(fp==NULL)
{
printf(" File Not Found: ");
getch();
exit(1);
}
fscanf(fp,"%c",&ch);
while(1)
{
printf("%c",ch);
fscanf(fp,"%c",&ch);
if(feof(fp))
break;
}
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.