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.
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;
}
4 comment threads