Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #define size 100
- char list[size],val;
- FILE *fp;
- int position=-1,select =0,pe,all,dpe;
- void insert(){
- printf("\n Enter the Element to insert \n");
- fprintf(fp,"\n Enter the Element to insert \n");
- scanf(" %c",&val);
- position = position + 1;
- list[position]=val;
- }
- void delete(){
- if(position == -1){
- fprintf(fp,"The list is empty \n");
- }
- else{
- printf("Enter the positon of the element to Delete \n");
- fprintf(fp,"Enter the positon of the element to Delete \n");
- scanf("%d",&pe);
- int i;
- for ( i = pe-1 ;i<=position;i++)
- {
- list [i]=list[i+1];
- }
- position = position -1;
- }}
- void display(){
- printf("Press 1 to display all the list Items otherwise press any alphanumeric key\n");
- fprintf(fp,"Press 1 to display all the list Items otherwise press any alphanumeric key\n");
- scanf("%d",&all);
- if (all==1){
- int i;
- for ( i = 0;i<=position;i++){
- printf("%c",list[i]);
- fprintf(fp,"%c",list[i]);
- }
- }
- else{
- printf("Enter the postion of the item to display\n");
- fprintf(fp,"Enter the postion of the item to display\n");
- scanf(" %d",&dpe);
- printf("%c",list[dpe-1]);
- fprintf(fp,"%c",list[dpe-1]);
- }
- printf("\n");
- fprintf(fp,"\n");
- }
- int main()
- {
- fp = fopen("074BCT035_LAB2.txt","a");
- while(1){
- printf("1.INSERT \n 2.DELETE \n 3.DISPLAY \n 4.EXIT \n");
- fprintf(fp,"1.INSERT \n 2.DELETE \n 3.DISPLAY \n 4.EXIT \n");
- scanf("%d",&select);
- switch(select){
- case 1:
- insert();
- break;
- case 2:
- delete();
- break;
- case 3:
- display();
- break;
- default:
- exit(0);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment