Advertisement
TheRandomTroll

Untitled

Jun 5th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.51 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct comment_t {
  4.     char author[64];
  5.     char content[64];
  6. };
  7.  
  8. struct post_t {
  9.     char title[64];
  10.     char content[512];
  11.     unsigned long date_posted;
  12.     unsigned long date_edited;
  13.  
  14.     struct comment_t comments[64];
  15.     int comments_count;
  16. };
  17.  
  18. struct blog_t {
  19.     struct post_t posts[20];
  20.     int posts_count;
  21.     char *author_name;
  22.     char *blog_title;
  23.     unsigned long last_change;
  24. };
  25.  
  26. int put_post(struct post_t, struct blog_t*);
  27. int display_posts(struct blog_t, unsigned long, unsigned long);
  28. int add_comment(struct comment_t, struct blog_t*, int);
  29.  
  30. int main() {
  31.     struct blog_t blog = { {}, 0, "Gosho", "This is my world", 1528179440 };
  32.     return 0;
  33. }
  34.  
  35. int put_post(struct post_t post, struct blog_t *blog) {
  36.     if(blog->posts_count == 20) return -1;
  37.     blog->posts[blog->posts_count++] = post;
  38.     return 0;
  39. }
  40.  
  41. int display_posts(struct blog_t blog, unsigned long s_time, unsigned long e_time) {
  42.     int count = 0;
  43.     for(int i = 0; i < blog.posts_count; i++) {
  44.         struct post_t post = blog.posts[i];
  45.         if(post.date_posted >= s_time && post.date_posted <= e_time) {
  46.             printf("%s (Comments: %d)\n", post.title, post.comments_count);
  47.             count++;
  48.         }
  49.     }
  50.  
  51.     return count;
  52. }
  53.  
  54. int add_comment(struct comment_t comment, struct blog_t* blog, int number) {
  55.     if(blog->posts[number].comments_count == 64) return -1;
  56.     blog->posts[number].comments[blog->posts[number].comments_count++] = comment;
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement