Showing posts with label File Handling. Show all posts
Showing posts with label File Handling. Show all posts
Saturday, January 22, 2011
What is header file in c?
Include directory is special directory which content all the header files of c language. Extension of header files in c language is h. All header files only keep declaration of functions, declaration of data type and micro constants. Body of function i.e. function definition is not written in the header files. Hence no one can get source code of function like printf, clrscr etc. All the
Saturday, August 7, 2010
How to write to a file in c
.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px
How to open a file in c
.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px
How to read a file in c
.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px
Saturday, June 19, 2010
Write a c program to find out the size and drive where file has stored of any given file?
#include "time.h"
#include "sys\stat.h"
#include "stdio.h"
int main(){
struct stat status;
FILE *fp;
fp=fopen("test.txt","r");
fstat(fileno(fp),&status);
printf("Size of file : %d",status.st_size);
printf("Drive name : %c",65+status.st_dev);
return 0;
}
Explanation:
Function int fstat (char *, struct stat *) store the information of open file in
#include "sys\stat.h"
#include "stdio.h"
int main(){
struct stat status;
FILE *fp;
fp=fopen("test.txt","r");
fstat(fileno(fp),&status);
printf("Size of file : %d",status.st_size);
printf("Drive name : %c",65+status.st_dev);
return 0;
}
Explanation:
Function int fstat (char *, struct stat *) store the information of open file in
Write a c program to know the last date of modification of any file
#include "time.h"
#include "sys\stat.h"
#include "stdio.h"
int main(){
struct stat status;
FILE *fp;
fp=fopen("test.txt","r");
fstat(fileno(fp),&status);
printf("Last date of modification : %s",ctime(&status.st_ctime));
return 0;
}
Explanation:
Function int fstat(char *, struct stat *) store the information of open file in form of structure struct
Monday, June 7, 2010
How to read a text file by c program
.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px
Wednesday, September 9, 2009
Write a C program which output is source code itself
C program to get source code of current program that is program itself
#include
void main()
{
FILE *p;
char ch;
clrscr();
p=fopen("raja.c","r");
while((ch=getc(p))!=-1)
putchar(ch);
fclose(p);
getch();
}
WAP in c to write an array into the file
#include<>stdio.h>void main(){ FILE *p; int i,a[10]; if((p=fopen("myfile.dat","wb"))==NULL) { printf("\nUnable to open file myfile.dat"); exit(1); } printf("\nEnter ten values, one value on each line\n"); for(i=0;i<10;i++) scanf("%d",&a[i]); fwrite(a,sizeof(a),1,p); fclose(p); getch();}
C program to read text from file
#includevoid main(){ char str[70]; FILE *p; clrscr(); if((p=fopen("string.txt","r"))==NULL) { printf("\nUnable t open file string.txt"); exit(1); } while(fgets(str,70,p)!=NULL) puts(str); fclose(p);}
Write a c program to write text in the file
#includevoid main(){ FILE *p; char str[70]; if((p=fopen("string.txt","w"))==NULL) { printf("\nUnable to open file string.txt"); exit(1); } else printf("\nEnter a set of strings,Press just enter key to finish\n: "); while(strlen(gets(str))>0) { fputs(str,p); fputs("\n",p); } fclose(p); getch();}
What is difference between file opening mode r+ and w+ in c?
Both r+ and w+ we can read ,write on file but r+ does not truncate (delete) the content of file as well it doesn�t create a new file if such file doesn�t exits while in w+ truncate the content of file as well as create a new file if such file doesn�t exists.
WRITE A C PROGRAM TO FIND SIZE OF A FILE
C program to get total file size
#include
#include
#include
void main()
{
struct stat status;
FILE *fp;
fp=fopen("test.txt","r");
fstat(fileno(fp),&status);
clrscr();
printf("Size of file : %d",status.st_size);
printf("Drive name : %c",65+status.st_dev);
getch();
}
Explanation:
Function int
WHAT IS FILE?
File is named location of stream of bits. It may be stored at singe place or different places but it represents a single stream.
Tuesday, September 8, 2009
FILE HANDLING TUTORIAL IN C
What is file?
What is stream?
What is FILE pointer?
What is buffer?
How can we know size and drive where file has stored of any given file?
Find out the last date of modification of any given file?
How can we know read/write permission any given file?
How can we know, given file is regular file, character special or it is directory?
What is difference between file opening
CONCATENATE MANY FILES AND STORE THEM IN A FILE IN C
.fieldsetOut{
background:#1E90FF;
padding:0px 0px 0px 0px;
font-family: "courier new"
}
.fieldsetIn{
background:white;
margin:1px 1px 1px 1px;
padding:1px 1px 1px 1px;
border: 0px 0px 0px 0px
}
.explanation{
color:#800000;
font-size:25px;
font-weight:900;
letter-spacing:15
}
Concatenate
many files and store them in a file in c programming language
#include
Subscribe to:
Posts (Atom)