Advertisement
rodan0818

Implementation_Of_List_using_Cprogramming

May 23rd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.62 KB | None | 0 0
  1. #include <Stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #define size 100
  5. char list[size],val;
  6. FILE *fp;
  7. int position=-1,select =0,pe,all,dpe;
  8. void insert(){
  9. printf("\n Enter the Element to insert \n");
  10. fprintf(fp,"\n Enter the Element to insert \n");
  11. scanf(" %c",&val);
  12. position = position + 1;
  13. list[position]=val;
  14. }
  15. void delete(){
  16.     if(position == -1){
  17.         fprintf(fp,"The list is empty \n");
  18.     }
  19.     else{
  20. printf("Enter the positon of the element to Delete \n");
  21. fprintf(fp,"Enter the positon of the element to Delete \n");
  22. scanf("%d",&pe);
  23. int i;
  24. for ( i = pe-1 ;i<=position;i++)
  25. {
  26. list [i]=list[i+1];
  27. }
  28. position = position -1;
  29. }}
  30. void display(){
  31.  printf("Press 1 to display all the list Items otherwise press any alphanumeric key\n");
  32.  fprintf(fp,"Press 1 to display all the list Items otherwise press any alphanumeric key\n");
  33.  scanf("%d",&all);
  34.  if (all==1){
  35. int i;
  36. for ( i = 0;i<=position;i++){
  37. printf("%c",list[i]);
  38. fprintf(fp,"%c",list[i]);
  39. }
  40. }
  41. else{
  42. printf("Enter the postion of the item to display\n");
  43. fprintf(fp,"Enter the postion of the item to display\n");
  44. scanf(" %d",&dpe);
  45. printf("%c",list[dpe-1]);
  46. fprintf(fp,"%c",list[dpe-1]);
  47. }
  48. printf("\n");
  49. fprintf(fp,"\n");
  50. }
  51. int main()
  52. {
  53.     fp = fopen("074BCT035_LAB2.txt","a");
  54. while(1){
  55.     printf("1.INSERT \n 2.DELETE \n 3.DISPLAY \n 4.EXIT \n");
  56.     fprintf(fp,"1.INSERT \n 2.DELETE \n 3.DISPLAY \n 4.EXIT \n");
  57.     scanf("%d",&select);
  58.     switch(select){
  59.     case 1:
  60.     insert();
  61.     break;
  62.     case 2:
  63.     delete();
  64.     break;
  65.     case 3:
  66.     display();
  67.     break;
  68.     default:
  69.     exit(0);
  70.     }
  71.     }
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement