Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. int main(int argc, char const *argv[])
  2. {
  3.     int article;
  4.     List *previous;
  5.     char answ;
  6.     // Creating article
  7.     for (int article = 0; article < sizeof (plist)/sizeof (List*); article++)
  8.     {
  9.         printf ("Do you want to add article? [Y|N] ");
  10.         answ = getchar ();
  11.         if (tolower (answ) == 'n')
  12.             break;
  13.         clear_stdin ();
  14.        
  15.         // Allocate memory for new article
  16.         printf( "article = %d\n", article);
  17.         plist[article] = malloc (sizeof (List*));
  18.         if (!plist[article]) {
  19.             printf ("\nNot enough memory, try again.\n");
  20.             abort ();
  21.         }
  22.        
  23.         // Get article title
  24.         printf ("\nEnter title of your new article: ");
  25.         fgets (buf, BUF_SIZE, stdin);
  26.         strncpy (plist[article]->title, buf, TITLE_SIZE);
  27.         clear_stdin ();
  28.        
  29.         // Get article text
  30.         printf ("\nEnter text of your new article:\n");
  31.         fgets (buf, BUF_SIZE, stdin);
  32.         strncpy (plist[article]->data, buf, TEXT_SIZE);
  33.         clear_stdin ();
  34.        
  35.         // Saving article
  36.         printf ("Do you want to save this article? [Y|N]\n");
  37.         preview_article (plist[article]);
  38.         answ = getchar ();
  39.         clear_stdin ();
  40.  
  41.         if (tolower (answ) == 'n') {
  42.             free (plist[article]);
  43.             article--;
  44.             continue;
  45.         }
  46.         if (article > 0)
  47.         {
  48.             plist[article]->prev = previous;
  49.             previous->next = plist[article];
  50.         }
  51.         else
  52.             plist[article]->prev = NULL;
  53.         previous = plist[article];
  54.     }
  55. }
  56.  
  57. // malloc(): corrupted top size
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement