Returning a string

This is a discussion on Returning a string within the C Programming forums, part of the General Programming Boards category; I'm writing a small program to catalog my comic book collection. One of my function is used to return the ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    3

    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;
    }

  2. #2
    orbitz_school
    Guest
    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).

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, 01:11 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21