CAT | Data structure
18
Decwrite a prog. to copy one file to another
0 Comments | Posted by Jex kanani in Data structure
void main()
{
FILE *fp1,*fp2;
char ch; clrscr();
fp1=fopen("d:\\sy42\\303\\aaa.txt","r");
fp2=fopen("d:\\sy42\\303\\bbb.txt","w");
if(fp1==NULL)
{ printf("\nnot read");
exit();
}
if(fp2==NULL)
{ printf("\nnot read");
fclose(fp1);
exit();
}
ch=fgetc(fp1);
while(ch!=EOF)
{
fputc(ch,fp2);
ch=fgetc(fp1);
}
fclose(fp1);
fclose(fp2);
printf("\n copied successfully");
getch();
}
{
FILE *fp1,*fp2;
char ch; clrscr();
fp1=fopen("d:\\sy42\\303\\aaa.txt","r");
fp2=fopen("d:\\sy42\\303\\bbb.txt","w");
if(fp1==NULL)
{ printf("\nnot read");
exit();
}
if(fp2==NULL)
{ printf("\nnot read");
fclose(fp1);
exit();
}
ch=fgetc(fp1);
while(ch!=EOF)
{
fputc(ch,fp2);
ch=fgetc(fp1);
}
fclose(fp1);
fclose(fp2);
printf("\n copied successfully");
getch();
}
18
Decwrite a prog. to find number of characters,words,lines in a file.
0 Comments | Posted by Jex kanani in Data structure
void main()
{
FILE *fp;
char ch;
int nol=0,not=0,nob=0,noc=0;
clrscr();
fp=fopen("f1.txt","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
noc++;
if(ch==' ')
nob++;
if(ch=='\n')
nol++;
if(ch=='\t')
not++;
}
fclose(fp);
printf("no.of char=%d",noc);
printf("no.of blanks=%d",nob);
printf("no.of tabs=%d",not);
printf("no.of lines=%d",nol);
getch();
}
{
FILE *fp;
char ch;
int nol=0,not=0,nob=0,noc=0;
clrscr();
fp=fopen("f1.txt","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
noc++;
if(ch==' ')
nob++;
if(ch=='\n')
nol++;
if(ch=='\t')
not++;
}
fclose(fp);
printf("no.of char=%d",noc);
printf("no.of blanks=%d",nob);
printf("no.of tabs=%d",not);
printf("no.of lines=%d",nol);
getch();
}
18
DecWrite a menu driven program to carry out following operations on array. a.Traversing b.Insertion c.Deletion d.Sorting e.Searching
0 Comments | Posted by Jex kanani in Data structure
void main()
{
int ch,h[10],n,p,i,t,j;
printf("\n ENTER ARRAY= ");
for(i=0;i<10;i++)
{
scanf("\n %d",&h[i]);
}
do
{
clrscr();
flushall();
printf("\n1.traversing");
printf("\n2.insertion");
printf("\n3.deletion");
printf("\n4.sorting");
printf("\n5.searching");
printf("\n6. exit");
printf("\nenter choice");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\n display array");
for(i=0;i<10;i++)
{
printf("\n %d",h[i]);
} getch();
break;
case 2:printf("\n enter no & position ");
scanf("%d%d",&n,&p);
for(i=0;i<10;i++)
{
if(i==p)
{
h[i]=n;
}
else
{
printf("\n position not found");
}
}
break;
case 3: printf("\n enter position for delete no");
scanf("%d",&n);
for(i=0;i<10;i++)
{
if(i==n)
{
h[i]=0;
}
else
{
printf("\n position not found");
}
}
break;
case 4:printf("\n sorting is==");
for(i=0;i<9;i++)
{
for(j=i+1;j<=9;j++)
{
if(h[i]<=h[j])
{
t=h[i];
h[i]=h[j];
h[j]=t;
}
}
}
for(i=0;i<10;i++)
{
printf("\n%d\n",h[i]);
} getch();
break;
case 5: printf("\n enter no for searching ");
scanf("%d",&n);
for(i=0;i<10;i++)
{
if(h[i]==n)
printf("\n%d",h[i]);
} getch();
break;
case 6:exit();
}
}while(ch!=6);
getch();
}
{
int ch,h[10],n,p,i,t,j;
printf("\n ENTER ARRAY= ");
for(i=0;i<10;i++)
{
scanf("\n %d",&h[i]);
}
do
{
clrscr();
flushall();
printf("\n1.traversing");
printf("\n2.insertion");
printf("\n3.deletion");
printf("\n4.sorting");
printf("\n5.searching");
printf("\n6. exit");
printf("\nenter choice");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\n display array");
for(i=0;i<10;i++)
{
printf("\n %d",h[i]);
} getch();
break;
case 2:printf("\n enter no & position ");
scanf("%d%d",&n,&p);
for(i=0;i<10;i++)
{
if(i==p)
{
h[i]=n;
}
else
{
printf("\n position not found");
}
}
break;
case 3: printf("\n enter position for delete no");
scanf("%d",&n);
for(i=0;i<10;i++)
{
if(i==n)
{
h[i]=0;
}
else
{
printf("\n position not found");
}
}
break;
case 4:printf("\n sorting is==");
for(i=0;i<9;i++)
{
for(j=i+1;j<=9;j++)
{
if(h[i]<=h[j])
{
t=h[i];
h[i]=h[j];
h[j]=t;
}
}
}
for(i=0;i<10;i++)
{
printf("\n%d\n",h[i]);
} getch();
break;
case 5: printf("\n enter no for searching ");
scanf("%d",&n);
for(i=0;i<10;i++)
{
if(h[i]==n)
printf("\n%d",h[i]);
} getch();
break;
case 6:exit();
}
}while(ch!=6);
getch();
}
18
DecWrite a function to count positive and negative numbers of array.
0 Comments | Posted by Jex kanani in Data structure
void main()
{
int a[10];int i;clrscr();
printf("\nenter values for array");
for(i=0;i<10;i++)
{scanf("%d",&a[i]);
}
count(&a[0]);
getch();
}
void count(int *x)
{
int i,m=0,n=0;
for(i=0;i<10;i++)
{
if(x[i]< 0)
{ m++;}
else
{n++;
} }
printf("\n total positive value=%d",n);
printf("\n total negative value=%d",m); }
/*
{
int a[10];int i;clrscr();
printf("\nenter values for array");
for(i=0;i<10;i++)
{scanf("%d",&a[i]);
}
count(&a[0]);
getch();
}
void count(int *x)
{
int i,m=0,n=0;
for(i=0;i<10;i++)
{
if(x[i]< 0)
{ m++;}
else
{n++;
} }
printf("\n total positive value=%d",n);
printf("\n total negative value=%d",m); }
/*
18
DecWrite a program to demonstrate pointer to function.
0 Comments | Posted by Jex kanani in Data structure
void main()
{
void * display();
void (*ptr) ();
//display();
ptr=display();
(*ptr) ();
getch();
}
void * display()
{
printf("\n this is function");
}
/*
output :
this is function
*/
{
void * display();
void (*ptr) ();
//display();
ptr=display();
(*ptr) ();
getch();
}
void * display()
{
printf("\n this is function");
}
/*
output :
this is function
*/
![[del.icio.us]](http://www.itshala.com/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.itshala.com/wp-content/plugins/bookmarkify/digg.png)
![[dzone]](http://www.itshala.com/wp-content/plugins/bookmarkify/dzone.png)
![[Facebook]](http://www.itshala.com/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://www.itshala.com/wp-content/plugins/bookmarkify/google.png)
![[LinkedIn]](http://www.itshala.com/wp-content/plugins/bookmarkify/linkedin.png)
![[Twitter]](http://www.itshala.com/wp-content/plugins/bookmarkify/twitter.png)
![[Windows Live]](http://www.itshala.com/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.itshala.com/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://www.itshala.com/wp-content/plugins/bookmarkify/email.png)
