Program to write some contents into a file using file
operations with proper error messages.
Answers were Sorted based on User's Feedback
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 |
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 |
What is realloc in c?
Explain the difference between struct and union.
what will the following program do? void main() { int i; char a[]="String"; char *p="New Sring"; char *Temp; Temp=a; a=malloc(strlen(p) + 1); strcpy(a,p); //Line no:9// p = malloc(strlen(Temp) + 1); strcpy(p,Temp); printf("(%s, %s)",a,p); free(p); free(a); } //Line no 15// a) Swap contents of p & a and print:(New string, string) b) Generate compilation error in line number 8 c) Generate compilation error in line number 5 d) Generate compilation error in line number 7 e) Generate compilation error in line number 1
What's wrong with the call "fopen ("c:\newdir\file.dat", "r")"?
Write down the program to sort the array.
How can you restore a redirected standard stream?
which type of question asked from c / c++ in interview.
How do you redirect a standard stream?
Explain what standard functions are available to manipulate strings?
Explain how can you restore a redirected standard stream?
Is c is a low level language?
Explain a file operation in C with an example.