Program to write some contents into a file using file
operations with proper error messages.

Answers were Sorted based on User's Feedback



Program to write some contents into a file using file operations with proper error messages...

Answer / manvitha

//writing into a file
main()
{
char c;
FILE *fp;
fp=fopen("infor.dat",'w');
printf("enter data \n enter tab & enter a stop\n");
do
{
c=getchar();
put c(c,fp);
}while(c!='\t');
fclose(fp);
getch();
}

Is This Answer Correct ?    6 Yes 2 No

Program to write some contents into a file using file operations with proper error messages...

Answer / vignesh1988i

#include<stdio.h>
#include<conio.h>
void main()
{
FILE *pointer;
char character;
pointer=fopen("hello.c","w"); /*there must be a file in your
path*/
if(pointer==NULL)
printf("CANT OPEN THE FILE ,ITS NOT PRESENT IN THE DIRECTORY");
else
{
fflush(stdin); /*a fun() used to clear the buffer memory*/
while(1)
{
scanf("%c",&ch);
fprintf(pointer,"%c",ch);
if(ch=='$')
break;
}
}
fclose(pointer);
getch();
}

Is This Answer Correct ?    4 Yes 4 No

Post New Answer

More C Interview Questions

A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?

0 Answers  


I have a varargs function which accepts a float parameter?

0 Answers  


Tell us the difference between these two : #include"stdio.h" #include<stdio.h> define in detial.

5 Answers  


There is a 100-story building and you are given two eggs. The eggs (and the building) have an interesting property that if you throw the egg from a floor number less than X, it will not break. And it will always brake if the floor number is equal or greater than X. Assuming that you can reuse the eggs which didn't broke; you got to find X in a minimal number of throws. Give an algorithm to find X in minimal number of throws.

5 Answers   Yahoo,


program to find the second largest word in a paragraph amongst all words that repeat more thn twice

4 Answers   CTS, iGate,






What is the difference between single charater constant and string constant?

0 Answers  


What is a program flowchart and explain how does it help in writing a program?

0 Answers  


What are the advantages of c preprocessor?

0 Answers  


What is the right type to use for boolean values in c? Is there a standard type?

0 Answers  


what is difference between array,strutter,union and pointers

3 Answers   CTS, Lovely Professional University, Mannar Company,


write a program to rearrange the array such way that all even elements should come first and next come odd

0 Answers  


how can f be used for both float and double arguments in printf? Are not they different types?

0 Answers  


Categories