Program to write some contents into a file using file
operations with proper error messages.
Answer Posted / 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 View All Answers
Is file a keyword in c?
What is realloc in c?
How to declare a variable?
Do you know pointer in c?
Describe explain how arrays can be passed to a user defined function
How will you declare an array of three function pointers where each function receives two ints and returns a float?
int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above
How can I write functions that take a variable number of arguments?
List the difference between a 'copy constructor' and a 'assignment operator' in C?
What do you mean by a sequential access file?
Should I learn c before c++?
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?
Explain what will the preprocessor do for a program?
What is the use of static variable in c?