Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Regarding the implementation of data structures.

Post

Regarding the implementation of data structures.

+2
−6

I'm attempting a question to do with data structures, file streams & linked lists. The code isn't complete yet as I am still halfway working on it. I am required to use data structures in the declaration section like so as shown in my code below. However, I'm still confused on what I should include in the double quotes for story.title, story.author & story.subject (I'm not sure if I'm doing it right too). Can anyone help me out? (Also my title, author and book should not exceed 49 characters)

```
#include<stdio.h>
#include<stdlib.h>
//#define MAX 49
int main (void){
   FILE *cfPtr; 
   struct book{ //the data structure that I am required to use
     char *title;
     char *author;
     char *subject; //subject[]
   };
   int operation;
   if ((cfPtr = fopen("library.dat","w")) == NULL){
    printf("File could not be opened...\n");
   }
   else {
        struct book aBook;
        struct book *aPtr;
        
        aBook.title = ""; //how should I write in the double quotes?
        aBook.author = ""; 
        aBook.subject = "";
        
        printf("Enter operation number:");
        scanf("%d", &operation)
        switch(operation){
            case 1:
            printf("Title:\n"); 
            scanf("%s", title); 
            printf("Author:");
            scanf("%s", author);
            printf("Subject:");
            scanf("%s", subject);
            break;
            case 2:
            printf("Enter Title:");
            scanf("%s", Title);
//Incomplete coding (still working on it)
//I'm planning to use switch case by looking at the question but I also have to use linked lists
            fprintf(cfPtr, "%s %s %s\n", title, author, subject); 
        }
        fclose(cfPtr); 
return 0;
}
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

4 comment threads

There is no code below, or anywhere else. (2 comments)
Please don't delete your question (1 comment)
Just type text (1 comment)
Regarding string handling, [this post](https://software.codidact.com/posts/284849) might be helpful (1 comment)
Please don't delete your question
Canina‭ wrote about 3 years ago

Please don't delete your question just because you've been able to solve the problem. Doing so invalidates the work by others in providing answers.