Thread: Returning a string

  1. #1
    Registered User
    Join Date
    Nov 2002

    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.issue,
    tempComic.month, tempComic.year, tempComic.title, tempComic.description);

    char getBook(struct comic tempComic)

    return *;

  2. #2
    char getBook(struct comic tempComic)
          return *;
    Try something like

    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).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please check my C++
    By csonx_p in forum C++ Programming
    Replies: 263
    Last Post: 07-24-2008, 09:20 AM
  2. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM