in C++ i need help finishing the last 2 queations ( 2 and 3 ) Here is what code
ID: 3697378 • Letter: I
Question
in C++ i need help finishing the last 2 queations ( 2 and 3 )
Here is what code i already have:
#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;
}
Explanation / Answer
2.
#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,"a");
for(i=1;i<=10;i++)
{
printf("enter the number - ");
scanf("%d",&n);
fprintf(fp, "%d ", n);
}
fclose(fp);
getch();
}
3.
#include <stdio.h>
#include <conio.h>
#include <process.h>
int main()
{
FILE *fp;
char ch;
clrscr();
fp=fopen("x.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.