Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct comment_t {
- char author[64];
- char content[64];
- };
- struct post_t {
- char title[64];
- char content[512];
- unsigned long date_posted;
- unsigned long date_edited;
- struct comment_t comments[64];
- int comments_count;
- };
- struct blog_t {
- struct post_t posts[20];
- int posts_count;
- char *author_name;
- char *blog_title;
- unsigned long last_change;
- };
- int put_post(struct post_t, struct blog_t*);
- int display_posts(struct blog_t, unsigned long, unsigned long);
- int add_comment(struct comment_t, struct blog_t*, int);
- int main() {
- struct blog_t blog = { {}, 0, "Gosho", "This is my world", 1528179440 };
- return 0;
- }
- int put_post(struct post_t post, struct blog_t *blog) {
- if(blog->posts_count == 20) return -1;
- blog->posts[blog->posts_count++] = post;
- return 0;
- }
- int display_posts(struct blog_t blog, unsigned long s_time, unsigned long e_time) {
- int count = 0;
- for(int i = 0; i < blog.posts_count; i++) {
- struct post_t post = blog.posts[i];
- if(post.date_posted >= s_time && post.date_posted <= e_time) {
- printf("%s (Comments: %d)\n", post.title, post.comments_count);
- count++;
- }
- }
- return count;
- }
- int add_comment(struct comment_t comment, struct blog_t* blog, int number) {
- if(blog->posts[number].comments_count == 64) return -1;
- blog->posts[number].comments[blog->posts[number].comments_count++] = comment;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement