Advertisement
niamulhasan

Untitled

Nov 4th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.64 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. struct node
  5. {
  6.     int id;
  7.     char name[15];
  8.     char phone[15];
  9.     struct node *next;
  10.     struct node *prev;
  11. }*head,*student,*temp,*tail,*p,*q,*s;
  12.  
  13. void profile()
  14. {
  15.  
  16.     q=head;
  17.     int s_id;
  18.     printf("\nEnter search student id : ");
  19.     scanf("%d",&s_id);
  20.     while(q!=NULL)
  21.     {
  22.         if(q->id==s_id)
  23.         {
  24.  
  25.             printf("\n\nID : ");
  26.             printf("%d",q->id);
  27.  
  28.             printf("\nName : ");
  29.             puts(q->name);
  30.  
  31.             printf("Number : ");
  32.             printf("%s\n",q->phone);
  33.         }
  34.  
  35.         q=q->next;
  36.     }
  37. }
  38.  
  39.  
  40. void input()
  41. {
  42.     head=(struct node *)malloc(sizeof(struct node));
  43.     tail = head;
  44.     FILE *fp;
  45.     fp=fopen("Student portal.txt","r");
  46.     int node_no = 1;
  47.     while(1)
  48.     {
  49.         if( feof(fp) )
  50.         {
  51.             break ;
  52.         }
  53.         student=(struct node *)malloc(sizeof(struct node));
  54.  
  55.         fscanf(fp,"%d",&student->id);
  56.  
  57.         fscanf(fp,"%s",&student->name);
  58.  
  59.         fscanf(fp,"%s",&student->phone);
  60.  
  61.  
  62.         student->next=NULL;
  63.         student->prev=tail;
  64.         tail->next=student;
  65.         tail=student;
  66.         if(node_no ==1)
  67.         {
  68.             head=student;
  69.         }
  70.  
  71.  
  72.         node_no++;
  73.     }
  74.     if(tail==head)
  75.     {
  76.         tail=NULL;
  77.     }
  78.     else
  79.     {
  80.         tail=tail->prev;
  81.         tail->next=NULL;
  82.     }
  83.     fclose(fp);
  84.     profile();
  85. }
  86.  
  87. void student_edit()
  88. {
  89.  
  90.     p=head;
  91.     int s_id,i=0;
  92.     printf("\nEnter search student id : ");
  93.     scanf("%d",&s_id);
  94.     FILE *fp;
  95.     fp=fopen("Student portal.txt","w+");
  96.     while(p!=NULL)
  97.     {
  98.  
  99.         if(p->id==s_id)
  100.         {
  101.             char name[20],phone[15];
  102.             getchar();
  103.             printf("\tEnter name(Single name) : ");
  104.             gets(name);
  105.             printf("\tEnter phone number : ");
  106.             gets(phone);
  107.  
  108.  
  109.  
  110.             fprintf(fp,"%d ",p->id);
  111.  
  112.             fprintf(fp,"%s ",name);
  113.  
  114.             fprintf(fp,"%s ",phone);
  115.  
  116.             printf("\n\t\t\t\t\t\t\tEdit successful");
  117.             i++;
  118.             getchar();
  119.             getchar();
  120.         }
  121.         else
  122.         {
  123.             fprintf(fp,"%d ",p->id);
  124.  
  125.             fprintf(fp,"%s ",p->name);
  126.  
  127.             fprintf(fp,"%s ",p->phone);
  128.  
  129.         }
  130.         p=p->next;
  131.     }
  132.  
  133.     fclose(fp);
  134.     if(i==0)
  135.     {
  136.         printf("\n\t\t\t\t\t\t\tNot found");
  137.         getchar();
  138.         getchar();
  139.     }
  140.     input();
  141. }
  142. void student_del()
  143. {
  144.  
  145.     p=head;
  146.  
  147.     int s_id,i=0;
  148.     printf("\nEnter search student id : ");
  149.     scanf("%d",&s_id);
  150.     FILE *fp;
  151.     fp=fopen("Student portal.txt","w+");
  152.     while(p!=NULL)
  153.     {
  154.  
  155.         if(p->id==s_id)
  156.         {
  157.             printf("\nDelete successful");
  158.             i++;
  159.             getchar();
  160.             getchar();
  161.         }
  162.         else
  163.         {
  164.             fprintf(fp,"%d ",p->id);
  165.  
  166.             fprintf(fp,"%s ",p->name);
  167.  
  168.             fprintf(fp,"%s ",p->phone);
  169.  
  170.         }
  171.         p=p->next;
  172.     }
  173.     fclose(fp);
  174.  
  175.     if(i==0)
  176.     {
  177.         printf("\nNot found");
  178.         getchar();
  179.         getchar();
  180.     }
  181.     input();
  182.  
  183. }
  184. void sinup()
  185. {
  186.     int id;
  187.     char name[15],phone[15];
  188.     printf("\nEnter your name : ");
  189.     gets(name);
  190.  
  191.     printf("\nEnter your Phone Number : ");
  192.     scanf("%s",&phone);
  193.     printf("\nEnter your ID : ");
  194.     scanf("%d",&id);
  195.  
  196.  
  197.     FILE *fp;
  198.     fp=fopen("Student portal.txt","a+");
  199.     fprintf(fp,"%d ",id);
  200.  
  201.     fprintf(fp,"%s ",name);
  202.  
  203.     fprintf(fp,"%d ",phone);
  204.  
  205.     fclose(fp);
  206.     system("cls");
  207.  
  208.  
  209. }
  210. void main()
  211. {
  212.     system("COLOR 0B");
  213.  
  214.     input();
  215.  
  216.  
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement