Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char const *argv[])
- {
- int article;
- List *previous;
- char answ;
- // Creating article
- for (int article = 0; article < sizeof (plist)/sizeof (List*); article++)
- {
- printf ("Do you want to add article? [Y|N] ");
- answ = getchar ();
- if (tolower (answ) == 'n')
- break;
- clear_stdin ();
- // Allocate memory for new article
- printf( "article = %d\n", article);
- plist[article] = malloc (sizeof (List*));
- if (!plist[article]) {
- printf ("\nNot enough memory, try again.\n");
- abort ();
- }
- // Get article title
- printf ("\nEnter title of your new article: ");
- fgets (buf, BUF_SIZE, stdin);
- strncpy (plist[article]->title, buf, TITLE_SIZE);
- clear_stdin ();
- // Get article text
- printf ("\nEnter text of your new article:\n");
- fgets (buf, BUF_SIZE, stdin);
- strncpy (plist[article]->data, buf, TEXT_SIZE);
- clear_stdin ();
- // Saving article
- printf ("Do you want to save this article? [Y|N]\n");
- preview_article (plist[article]);
- answ = getchar ();
- clear_stdin ();
- if (tolower (answ) == 'n') {
- free (plist[article]);
- article--;
- continue;
- }
- if (article > 0)
- {
- plist[article]->prev = previous;
- previous->next = plist[article];
- }
- else
- plist[article]->prev = NULL;
- previous = plist[article];
- }
- }
- // malloc(): corrupted top size
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement