Beruflich Dokumente
Kultur Dokumente
Important Questions
_________________________________________________________________________
UNIT - III
Pointer and Arrays : Pointers and addresses, Pointers and Arrays, Pointers And function arguments, Address
arithmetic, character pointers and functions, pointers to pointers, multi-dimensional arrays, initialization of
pointer arrays, command line arguments, pointers to functions.
_________________________________________________________________________
UNIT - IV
Structures : Definition, initializing, assigning values, passing of structures as arguments, Arrays of structures,
pointers to structures, self referential structures. Unions, typedef, bit fields, C program examples.
_________________________________________________________________________
UNIT - V
Console & File I/O : Standard I/O, Formatted I/O, opening & closing of files, I/O operations on files.
1.What are the commonly used input/ output functions in C? How are they accessed?
2.What is the purpose of getchar, putchar functions? How is it used in a C Program? How is
it different from getc () and putc () functions?
3. What is the difference between getchar(), fgetchar(), getch(), getche().
4. What is the difference between printf(), sprintf(), fprintf(), write(), fwrite().
5. Write xgets() and xputs() which work similar to the standard library function gets() and
puts()
6. Write down a function getint() which would receive a numeric string from the keyboard,
convert it to an integer number and return the integer to the calling function. A sample usage
of getint() is shown below:
main(0
{
int a;
a=getint();
printf(“you entered %d”,a);
}
7. What are the arguments that can be used with function main()? Give an illustrative
example for main function arguments.
8. Write a programme to count the number of words in a file.
9. Write a programme to remove all comments from a file.
10.Write a programme to remove all blanks from a file.
11.Write a programme to store every character typed at the keyboard into a file. The
procedure should come to an end as soon as the character ~ is hit from the keyboard.
12.Write a C program to write a string to a file and read the same from the file
simultaneously counting the number of blank spaces, lines and characters in the string
13. Write a programme to encrypt / decrypt a file using:
(a) An offset cipher: In an offset cipher each character from the source file is offset with a
fixed value and then written to the target file. For example, if character read from the
source file is ‘A’, then convert this into a new character by offsetting ‘A’ by a fixed
value say 128, and then writing the new character to the target file.
(b) A substitution cipher: In this each character read from the source file substituted by a
predetermined character and this character is written to the target file. For example, if
character ‘A’ is to be substituted by ‘!’, then a’!’ would be written to the target file in
place of every ‘A’. Similarly every ‘B’ would be substituted by ‘5’ and so on (as
decided by the encryptor)
14. Illustrate the terms NULL and EOF in the context of file operations
_________________________________________________________________________
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
{ char ch;
FILE *fin,*fout;
clrscr();
if(argc!=3)
{
puts("insufficient arguments kindly renter");
exit(0);
}
fin = fopen(argv[1],"r");
if(fin==NULL)
{puts("cannot open source file");
exit(0);
}
fout = fopen(argv[2],"w");
if(fout==NULL)
{puts("cannot open target file");
exit(0);
}
while(1)
{
ch=fgetc(fin);
if(ch==EOF)break;
fputc(ch,fout);
}
fclose(fin);
fclose(fout);
getch();
_________________________________________________________________________
#include <stdio.h>
#include <conio.h>
main()
{ int *ptr,**ptr1,a=5;
clrscr();
ptr=&a;
ptr1=&ptr;
printf("1.%d\n",a);
printf("2.%d\n",*ptr);
printf("3.%d\n",**ptr1);
printf("1.%u\n",&a);
printf("2.%u\n",ptr);
printf("3.%u\n",*ptr1);
scanf("%d",ptr);
printf("1.%d\n",a);
scanf("%d",*ptr1);
printf("1.%d\n",a);
getch();
_________________________________________________________________________
showbits(n); bit_print(n);
getch(); getch();
} }
_________________________________________________________________________
#include <stdio.h>
#include <conio.h>
main()
{int i,count=0;
char name[11],search; /* array size is defined in the main*/
char* cp;
clrscr();
_____________________________________________________________________
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
main()
{ char *cp,*dup,search;
int count=0,len=0;
clrscr();
dup=cp=malloc(11*sizeof(char));
fflush(stdin);
printf("Enter a character to be searched :\n");
scanf("%c",&search);
fflush(stdin);
printf("Enter a string length less than 10 characters :\n");
_________________________________________________________________________
getch();
}
____________________________________________________________
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
main()
{ char *cp,*dup,search;
int count=0,len=0,siz;
clrscr();
printf("Enter thesize ofthe chunk in positive integer : ");
scanf("%d",&siz);
dup=cp=malloc(siz*sizeof(char));
fflush(stdin);
printf("Enter a character to be searched :\n");
scanf("%c",&search);
fflush(stdin);
printf("Enter a string length less than %d characters :\n",siz-1);
getch();
}
_________________________________________________________________________