You are on page 1of 4

ques 3

#include<conio.h>
#include<stdlib.h>
void main(int arg,char *arr[])
{
FILE *fs,*ft;
char ch;
clrscr();
if(arg!=3)
{
printf("Argument Missing ! Press key to exit.");
getch();
exit(0);
}
fs = fopen(arr[1],"r");
if(fs==NULL)
{
printf("Cannot open source file ! Press key to exit.");
getch();
exit(0);
}
ft = fopen(arr[2],"w");
if(ft==NULL)
{
printf("Cannot copy file ! Press key to exit.");
fclose(fs);
getch();
exit(0);
}
while(1)
{
ch = getc(fs);
if(ch==EOF)
{
break;
}
else
putc(ch,ft);
}
printf("File copied succesfully!");
fclose(fs);
fclose(ft);
}

ques 5
void main()
{
FILE *fp1,*fp2;
char c;
fp1=fopen("file1.txt","a+");
fp2=fopen("file2.txt","r");
c=getc(fp2);
while(c!=EOF)
{
putc(c,fp1);
c=getc(fp2);
}
printf("The result of appending: Contents in file1.txt\n");
fseek(fp1,0,SEEK_SET);
c=getc(fp1);
while(c!=EOF)
{
printf("%c",c);
c=getc(fp1);
}
printf("\nDone\n");
fclose(fp1);
fclose(fp2);
}

ques 1
void main()
{
FILE *all,*even,*odd;
int number,i,records;
printf("INPUT THE TOTAL NUMBER OF RECORDS THAT U WANT TO ENTER
");
scanf("%d",& records);
all=fopen("ANYNUMBER","w");
for(i=1;i<=records;i++)
{
scanf("%d",&number);
if(number==-1)break;
putw(number,all);
}
fclose(all);
all=fopen("ANYNUMBER","r");
even=fopen("EVENNUMBER","w");
odd=fopen("ODDNUMBER","w");
while((number=getw(all))!=EOF)
{
if(number%2==0)
putw(number,even);
else
putw(number,odd);
}
fclose(all);
fclose(even);
fclose(odd);

even=fopen("EVENNUMBER","r");
odd=fopen("ODDNUMBER","r");
printf("
THE EVEN NUMBERS ARE");
while((number=getw(even))!=EOF)
printf(" %4d",number);
printf("
THE ODD NUMBERS ARE");
while((number=getw(odd))!=EOF)
printf(" %4d",number);
fclose(even);
fclose(odd);
}

ques 4
Sequential programming:
*In sequential programs, the program is under control
*The user is required to synchronize with the program:
1) Program tells user it s ready for more input
2)User enters more input and it is processed
*Examples:
1)Command-line prompts (DOS, UNIX)
2)LISP interpreters
Event driven:-
*Instead of a user synchronizing with the program, the program synhronizes with,
or reacts to, the user
*All communication from user to computer occurs via events and the code that han
dles the events
*An event is an action that happens in the system
1)A mouse button pressed or released
2)A keyboard key is hit
3)A window is moved, resized, closed, etc.

ques 2
#include <stdio.h>
void main()
{
FILE *fopen(), *fp;
int c , linecount;
char filename[40], reply[40];
printf( Enter file name: );
gets( filename );
fp = fopen( "aman.txt", r );
if ( fp == NULL )
{
printf( Cannot open %s for reading \n , filename );
exit();
}
linecount = 1 ;
reply[0] = \0 ;
c = getc( fp ) ;
while ( c != EOF && reply[0] != Q && reply[0] != q )
{
putchar( c ) ;
if ( c == \n )
linecount = linecount+ 1 ;
if ( linecount == 20 )
{
linecount = 1 ;
printf( [Press Return to continue, Q to quit] );
gets( reply ) ;
}
c = getc ( fp );
}
fclose( fp );
}

You might also like