Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct el{
  4.     int x;
  5.     struct el *next;
  6. }*start, *tmp, *p,*g1;
  7.  
  8. void push(int x);
  9. void izpis();
  10. void izbris(int b);
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.   FILE *pFile = fopen("text.txt","r");
  15.   int x,l;
  16.   while((x=getc(pFile))!=EOF)
  17.   {
  18.    push(x);
  19.   }
  20.   izpis();
  21.   fclose(pFile);
  22.   printf("\n");
  23.   printf("mesto izbrisa");
  24.   scanf("%d",&l);
  25.   izbris(l);
  26.   izpis();
  27.   system("PAUSE > NULL");  
  28.   return 0;
  29. }
  30.  
  31. void push(int x)
  32. {
  33.  tmp = (struct el*)malloc(sizeof(struct el));
  34.  tmp->x = x;
  35.  tmp->next = start;
  36.  start = tmp;  
  37. }
  38. void izpis()
  39. {
  40.     p = start;
  41.  while(p != NULL)
  42.  {
  43.         printf("%c",p->x);
  44.         p = p->next;  
  45.     }
  46. }
  47. void izbris(int b)
  48. {
  49.  int i,l;
  50.  l = b;
  51.  tmp = NULL;
  52.  g1 = start;
  53.  for(i=1;i<l;i++)
  54.  {
  55.         g1=g1->next;
  56.  }
  57.   tmp = g1;
  58.   g1 = tmp->next;
  59.   free(tmp);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement