-
Returning a string
I'm writing a small program to catalog my comic book collection. One of my function is used to return the book name, which is a string. My problem is that when the function returns the string its just one char not the entire string. Could someone suggest a way that I'll be able to return the whole string, not just the first letter of it. My code is below, the function in question is the char getBook(struct comic tempComic) function.
#include <stdio.h>
struct comic{ char *book, //Storage for book name
*title, //Storage for title of book
*month, //Storage for month of publication
*description; //Short description of cover art of book
int year, //Storage for year of publication
issue; //Storage for the issue number
}; //End strcut c
void comicPrint(struct comic tempComic)
{
printf("%s\nIssue: #%d %s %d\nTitle: %s\nCover Art: %s\n\n", tempComic.book, tempComic.issue,
tempComic.month, tempComic.year, tempComic.title, tempComic.description);
}
char getBook(struct comic tempComic)
{
return *tempComic.book;
}
-
Code:
char getBook(struct comic tempComic)
{
return *tempComic.book;
}
Try something like
Code:
char *getBook(struct comic *tempComic)
{
return tempComic->book;
}
Sending whole structures at at iem is memory intensive, just send a pointer. And a string is a char array, so you need to return a character array (inthis case a pointer to the string).