1 Assignment 1 Data Structures and Algorithms Pointers, Linked Lists & ADTs Due Date :…
- User
1 Assignment 1 Data Structures and Algorithms Pointers, Linked Lists & ADTs Due Date : 25 January, 2024 Total Marks: 100 General Instructions The assignment must be implemented in C. The submission format is given at the end of the assignment. Grading of the assignment would not only be based on the working of the functionalities required to be implemented, but also the quality of code that is written and performance in the viva during the evaluations. The deadline is strict and will not be extended. Resorting to any sort of plagiarism (as mentioned in the policy shared) would be heavily penalised. Some sections of the assignment have been marked as Bonus. Any marks lost in the non-bonus section, can be made up for by doing the Bonus section. It must be noted, that Bonus marks would not provide extra marks in the assignment, they can just cover up for lost marks in the non-bonus section. Social Media Platform ADT 2 • • • • • • The task involves defining and implementing a social media platform ADT, that can handle features related to posts, comments and replies via a set of commands through the terminal. 1 2.1 File Structure The code must be made modular, consisting of the following files to define and implement the required ADTs:
- post.h & post.c
- comment.h & comment.c 3. reply.h & reply.c
- platform.h & platform.c 5. main.c It is allowed to make any other helper files, if necessary. 2.2 Data Types [15] 2.2.1 Post [5] The posts on the social media platform must store the following information:
- Username : Username of the user posting (Always a single string) 2. Caption : Caption to the post by the user
- Comments : List of comments on the post, by different users 2.2.2 Comment [5] The comments on the posts must store the following information: 1. Username : Username of the user commenting
- Content : Content of the comment
- Replies : List of replies to the comment by different users 2
2.2.3 Platform [5] The social media platform ADT, must store the following information:
- Posts : Lists of posts stored in some order of the time they were posted at
- lastViewedPost : The last viewed post on the terminal. By view, it means the one of which the details were shown latestly. If this does not hold for any post, it is the most recently added post till now. Note: Make Platform a global instance as it will only be created once. 2.2.4 Reply [Bonus][5] The replies to the comments on a post must store the following information: 1. Username : Username of the user replying
- Content : Content of the reply 2.3 Functions [60] For each of the ADTs, implement the following functions: 2.3.1 Post [5] 2.3.2 Comment [5] Function Name Parameters Return Value Description createPost char* username, char* caption Post* Creates a post using the given param- eters, returning a pointer to it Function Name Parameters Return Value Description createComment char* username, char* content Comment *comment Creates a comment using the given pa- rameters, returning a pointer to it 3
- Assistant
- User
can you debug why my code is giving null pointer
- Assistant
- User
- Assistant
- User
I NEED COMPLETE CODE
- Assistant
- User
string input in c
- Assistant
In C, string input usually involves reading character arrays from the standard input. Since C strings are arrays of characters terminated by a null character (), it's important to manage memory and ensure that input operations do not overflow allocated buffers. Here are several ways to take string input in C:
- User
show me how to take input for addpost
- Assistant
To take input for
addPost, you would typically want to prompt the user for a username and a post caption, then calladdPostwith those inputs.Here's how you might write a function in
main.cthat asks for this input and then calls the appropriate function to add a new post to the platform: - User
input integer scanf in c
- Assistant
To read an integer using
scanfin C, follow these steps:- Declare an integer variable to hold the input value.
- Use the
scanffunction with the%dformat specifier to read an integer.
Here's an example:
#include <stdio.h> int main() { int number; printf("Enter an integer: "); scanf("%d", &number); // Note the use of & to pass the address of number // To guard against incorrect input, check the return value of scanf if (scanf("%d", &number) == 1) { // Input was successfully parsed as an integer printf("You entered: %d\n", number); } else { // Input was not an integer, handle error printf("Error: Invalid input. Please enter an integer.\n"); // Clear input buffer to remove invalid input int ch; while ((ch = getchar()) != '\n' && ch != EOF); // Optionally prompt again or exit } return 0; } - User
take input integer and pass value to function and define the function to print that imteger
- Assistant
Here is a simple example demonstrating how to take an integer input from the user, pass it to a function, and then have that function print the received integer value.
Code Explanation
- We define a function
printIntegerwhich takes an integer as an argument and prints it. - In
main, we declare an integer variable to store user input. - We use
scanfto read the integer from the standard input. - We pass the integer to
printIntegerto print it.
- We define a function
- User
in the code aboe declare platform as global
- Assistant
To declare the
Platforminstance as a global variable, you need to define it outside of themainfunction or any other functions, at the top level of your program file. This will make thePlatforminstance accessible from any function within the same translation unit (i.e., the same source file or other files that include its header, if you use the keyword). - User
provide me the code for main.c where we take the input
- Assistant
- User
- Assistant