Advertisement
Guest User

blabla

a guest
Dec 13th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct STUDENT {
  5.     int id;
  6.     char name[30];
  7.     struct STUDENT* next;
  8.     struct STUDENT* prev;
  9. } S;
  10.  
  11. int main() {
  12.     char name[30];
  13.     int num, i;
  14.     FILE* input = fopen("blabla.txt","r");
  15.     S* first = (S*)malloc(sizeof(S));
  16.     first->prev=NULL;
  17.     S* current = first;
  18.     S* temp;
  19.    
  20. while(fscanf(input,"%d %s",&current->id,current->name)==2)
  21.     {
  22.         current->next = (S*)malloc(sizeof(S));
  23.         temp = current;
  24.         current = current->next;
  25.         current->prev = temp;
  26.     }
  27. current->id = -1; //last one   
  28.  
  29. for(current=first; current->id!=-1; current=current->next)
  30.     printf("%d %s\n",current->id,current->name);
  31.    
  32. //  printf("%d %s\n",first->id,first->name);
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement