Warm welcome to every visitors

For all nepalis
 
HomeHome  ­CalendarCalendar  ­FAQFAQ  ­SearchSearch  ­MemberlistMemberlist  ­UsergroupsUsergroups  ­RegisterRegister  ­Log inLog in  
Latest topics
» Lab 8 solutions
Wed May 27, 2009 2:42 pm by Anonymous

» Criminal management system
Wed May 27, 2009 12:03 pm by krazzy

» File related lab solutions.
Wed May 27, 2009 12:01 pm by krazzy

» Simple boot virus(win98)
Wed May 27, 2009 11:46 am by krazzy

» Slambook(Student)
Wed May 27, 2009 11:44 am by krazzy

» Snake game
Wed May 27, 2009 11:40 am by krazzy

» Password cracker
Wed May 27, 2009 11:39 am by krazzy

» Hawdare partion tool
Wed May 27, 2009 11:36 am by krazzy

» Library management system
Wed May 27, 2009 11:33 am by krazzy

Search
 
 

Display results as :
 
Rechercher Advanced Search
Poll
What should be the fees range for first year?
200000-300000
80%
 80% [ 4 ]
300000-400000
20%
 20% [ 1 ]
400000-500000
0%
 0% [ 0 ]
Total Votes : 5
Hami first year ko frees kahile ghat cha??????
Sat Mar 07, 2009 12:25 pm by krazzy
What should be the fees range for first year?
Oye fees chadi ghataunu paryooooo............
cheers

Comments: 1
First yer bata chunab kasle jitcha hola???????????
Sat Mar 07, 2009 12:14 pm by Admin
Oye chunab kahile hune chance cha hola????
Any body of you know about this???????????
First year ko fee kati hunu parcha hola?????????

Comments: 0
C programming kasto lagcha??????????????
Sat Mar 07, 2009 12:10 pm by Admin
You can get lab questions solved here................

Comments: 0
Post new topic   Reply to topicShare | 
 

 File related lab solutions.

View previous topic View next topic Go down 
AuthorMessage
krazzy



Posts: 11
Join date: 2009-03-06
Age: 20
Location: New baneshwor,Kathmandu

PostSubject: File related lab solutions.   Wed May 27, 2009 12:01 pm

1.WAP to count the no. of characters,lines and words using file.
#include<stdio.h>
#include<conio.h>

void main()
{
FILE *fp;
char ch,fname[10];
int count=0,count1=0,count2=0;
clrscr();
printf("Enter the file name:");
gets(fname);
fp=fopen(fname,"w");
while((ch=getchar())!=EOF)
{
fputc(ch,fp);
}
fclose(fp);
fp=fopen(fname,"r");
while((ch=fgetc(fp))!=EOF)
{
count++;
if(ch=='\n')
count1++;
if(ch=='\n'||ch==' ')
count2++;
}
printf("The no. of characters is:%d\n",count);
printf("The no. of lines i:%d\n",count1+1);
printf("The no. of words is:%d\n",count2+1);
fclose(fp);
getch();
}

2.WAP to save a file with information in binary format.

#include<stdio.h>
#include<conio.h>
struct student
{
char name[20];
int age;
};
void main()
{
FILE *fp;
struct student st1;
clrscr();
fp=fopen("xyz.bin","wb");
if(fp==NULL)
{
printf("File cannot open.");
getch();
exit();
}
printf("Enter the name:");
scanf("%s",st1.name);
printf("Enter the age:");
scanf("%d",&st1.age);
fwrite(&st1,sizeof(struct student),1,fp);
fclose(fp);
getch();
}


2.WAP to the saved read data from a binary file.
#include<stdio.h>
#include<conio.h>
struct student
{
char name[20];
int age;
};
void main()
{
FILE *fp;
struct student st1;
clrscr();
fp=fopen("xyz.bin","rb");
if(fp==NULL)
{
printf("File can't open");
getch();
exit();
}
fread(&st1,sizeof(struct student),1,fp);
printf("name=%s\n",st1.name);
printf("age=%d",st1.age);
fclose(fp);
getch();
}
Back to top Go down
View user profile http://www.anepali.tk
 

File related lab solutions.

View previous topic View next topic Back to top 
Page 1 of 1

Permissions of this forum:You can reply to topics in this forum
Warm welcome to every visitors :: C programming-
Post new topic   Reply to topic