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

Dashboard
Notifications
Mark all as read
Q&A

Is this the correct way of receiving data structures of pointers as an input? [duplicate]

+0
−2

Closed as duplicate by Alexei‭ on Dec 8, 2021 at 12:34

This question has been addressed elsewhere. See: Regarding the implementation of data structures.

This question was closed; new answers can no longer be added. Users with the reopen privilege may vote to reopen this question if it has been improved or closed incorrectly.

How do you accept a data structure of pointer as an input?

#include<stdio.h>
#include<stdlib.h>

//void addBook(struct library* thislib){
//}
int main (void){
    
   FILE *cfPtr; 
   struct book{
     char *title;
     char *author;
     char *subject; 
   };

   int operation;

    if ((cfPtr = fopen("helloo.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 = "";

        instructions(); //display the menu
        printf("Enter operation number:");
        scanf("%d", &operation);
        switch(operation){
            case 1:
            printf("Title:\n"); 
            scanf("%s", aBook.title); //can I receive the input like this?
            printf("Author:");
            scanf("%s", aBook.author);
            printf("Subject:");
            scanf("%s", aBook.subject);

            fprintf(cfPtr, "%d %s %s %s\n", operation, aBook->title, aBook->author, aBook->subject);
            break;

This is just a part of my code

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

How is this question different? (1 comment)

0 answers