Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. struct list {
  7. char *string;
  8. struct list *next;
  9. };
  10.  
  11. typedef struct list LIST;
  12.  
  13. int main(void) {
  14. FILE *fp;
  15. char line[63];
  16. LIST *current, *head;
  17.  
  18. head = current = NULL;
  19. fp = fopen("dzimta.text", "r");
  20.  
  21. while(fgets(line, sizeof(line), fp))
  22. {
  23. if(line[0] != "\n"){
  24.  
  25. }else {continue;}
  26.  
  27. LIST *node = malloc(sizeof(LIST));
  28. node->string = strdup(line);
  29. node->next =NULL;
  30.  
  31. if(head == NULL){
  32. current = head = node;
  33. } else {
  34. current = current->next = node;
  35. }
  36. }
  37. fclose(fp);
  38. for(current = head; current ; current=current->next){
  39.  
  40. printf("%s", current->string);
  41. }
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement