Adv C Slip Only Quesn
Adv C Slip Only Quesn
Displaying Information:
Roll number: 1
Name: Tom
Marks: 98
Slip 2:-
Write a menu driven program to perform the following operations on
strings using standard library functions:
1. Convert string to uppercase
2. Copy one string to another
3. Compare two strings
4. Concatenate two strings
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
char s1[50],s2[50];
int ch,i;
printf("\nMenu :\n 1.Convert string to uppercase\n");
printf(" 2. Copy one string to another\n");
printf("3. Compare two strings\n 4. Concatenate two strings\n");
printf("5. Exit\n Enter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\n Enter String: ");
scanf("%s",s1);
printf("\n Converted String: ");
for(i=0;i<strlen(s1);i++)
printf("%c",toupper(s1[i]));
break;
case 2: printf("\n Enter String: ");
scanf("%s",s1);
strcpy(s2,s1);
printf("\n Copied String is : %s",s2);
break;
case 3: printf("\n Enter string1 : ");
scanf("%s",s1);
printf("\n Enter String2 : ");
scanf("%s",s2);
if(strcmp(s1,s2)==0)
printf("\n Entered strings are equal...");
else
printf("\n Entered strings are different..");
break;
case 4: printf("\n Enter string1 : ");
scanf("%s",s1);
printf("\n Enter string2 : ");
scanf("%s",s2);
printf("\n Concatenated string : %s",strcat(s1,s2));
break;
case 5: exit(0);
break;
default: printf("\n Enter proper choice");
} //end switch
return 0;
}
Slip 3:-
Write a program to declare a structure person (name, address) which
contains another structure birthdate (day, month, year). Accept the details
of n persons and display them.
#include <stdio.h>
struct student{
char name[30];
introllNo;
structdateOfBirth{
intdd;
int mm;
intyy;
}DOB;
};
int main()
{
struct student std;
printf("Enter name: "); gets(std.name);
printf("Enter roll number: "); scanf("%d",&std.rollNo);
printf("Enter Date of Birth [DD MM YY] format: ");
scanf("%d%d%d",&std.DOB.dd,&std.DOB.mm,&std.DOB.yy);
printf("\nName : %s \nRollNo : %d \nDate of birth : %02d/%02d/%02d\
n",std.name,std.rollNo,std.DOB.dd,std.DOB.mm,std.DOB.yy);
return 0;
}
OUTPUT:-
Enter name: Mike
Enter roll number: 101
Enter Date of Birth [DD MM YY] format: 14 03 92
Name : Mike
RollNo : 101
Date of birth : 14/03/92
Slip:-4
Write a program to copy contents of file a.txt to b.txt by changing the
case of each alphabet.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int main()
{
FILE *fp1,*fp2;
char ch;
fp1=fopen("a.txt","r");
fp2=fopen("b.txt","w");
if(!fp1)
printf("\n Error in reading..");
if(!fp2)
printf("\n Error in writing..");
else
{
while((ch=fgetc(fp1))!=EOF)
{
if(isupper(ch))
fputc(tolower(ch),fp2);
else
fputc(toupper(ch),fp2);
}
}
return 0;
}
Slip:-5
Write a program to read the contents of a text file and count the number of
characters, lines and words in the file.
#include <stdio.h>
#include <stdlib.h>
int main(){
FILE * file;
char path[100];
char ch;
int characters, words, lines;
file=fopen("counting.txt","w");
printf("enter the text.press cntrl Z:\n");
while((ch = getchar())!=EOF){
putc(ch,file);
}
fclose(file);
printf("Enter source file path: ");
scanf("%s", path);
file = fopen(path, "r");
if (file == NULL){
printf("\nUnable to open file.\n");
exit(EXIT_FAILURE);
}
characters = words = lines = 0;
while ((ch = fgetc(file)) != EOF){
characters++;
if (ch == '\n' || ch == '\0')
lines++;
if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\0')
words++;
}
if (characters > 0){
words++;
lines++;
}
printf("\n");
printf("Total characters = %d\n", characters);
printf("Total words = %d\n", words);
printf("Total lines = %d\n", lines);
fclose(file);
return 0;
}
Output
enter the text.press cntrl Z:
Hi welcome to Tutorials Point
C programming Articles
Best tutorial In the world
Try to have look on it
All The Best
Enter source file path: counting.txt
Slip 6:-
Write a C program to create structure employee (id, name, salary). Accept
details of n employees and perform the following operations:
a. Display all employees.
b. Display details of all employees having salary > ____.
#include<stdio.h>
#include<stdlib.h>
struct details
char name[30];
int eid;
int salary;
}emp[5];
void emp_search(int r)
int id,i;
scanf("%d",&id);
printf("----------------------------------------\n");
for(i=0;i<r;i++)
if(emp[i].eid==id)
printf("Employee Id : %d",emp[i].eid);
printf("\nName : %s",emp[i].name);
printf("\nSalary : %d\n",emp[i].salary);
}
}
void display(int r)
int i;
printf("-------------------------------\n");
printf("Emp-Id\tEmp-Name Salary\n");
printf("--------------------------------\n");
for(i=0;i<r;i++)
printf("%d\t%s\t %d\n",emp[i].eid,emp[i].name,emp[i].salary);
void greater(int r)
int i;
printf("------------------------------------------------");
for(i=0;i<r;i++)
if(emp[i].salary>10000)
int main()
int n,i,ch;
scanf("\n %d",&n);
for(i=0;i<n;i++)
printf("-----------------------------------------");
printf("\n-----------------------------------------");
scanf("%s",emp[i].name);
printf("Employee-Id : ");
scanf("%d",&emp[i].eid);
printf("Salary : ");
scanf("%d",&emp[i].salary);
while(1)
printf("-----------------------------------------\n");
printf("\t\tMenu\n");
printf("-----------------------------------------");
printf("\n 4:Exit");
printf("\n----------------------------------------\n");
scanf("\n %d",&ch);
switch(ch)
case 1: emp_search(n);
break;
case 2: display(n);
break;
case 3: greater(n);
break;
case 4: exit(0);
return 0;
}
Slip 7:-
Slip 8:-
Slip 9:-
Slip 10:-