Thread: Project help

  1. #1
    Registered User
    Join Date
    Aug 2014
    Posts
    2

    Project help

    Project help-untitled-png

    Project help-untitled2-png

    How to return as a pointer to a string?

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    The comment says it all. Is there something you're having problems with?
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Aug 2014
    Posts
    2
    Quote Originally Posted by GReaper View Post
    The comment says it all. Is there something you're having problems with?
    Yeah I wasnt sure how to approach the start the yearToString

  4. #4
    Registered User zub's Avatar
    Join Date
    May 2014
    Location
    Russia
    Posts
    104
    I think, "malloc in one function and free in other" is very bad thing. By the way, you needn't malloc at all. Just create a static array of constant strings and return appropriate string from array. What's problem?
    Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by zub View Post
    I think, "malloc in one function and free in other" is very bad thing.
    Sometimes it's the best option available though.
    Quote Originally Posted by zub View Post
    By the way, you needn't malloc at all. Just create a static array of constant strings and return appropriate string from array. What's problem?
    You mean apart from the fact it's at odds with the requirements of the OP's particular homework exercise?

    In general, use of statics imposes limits on ability to use a function. Such as non-reentrancy (and eliminating recursion), unsafe in multithreaded code, and it is often unsafe to use the function twice within one expression.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by grumpy
    In general, use of statics imposes limits on ability to use a function. Such as non-reentrancy (and eliminating recursion), unsafe in multithreaded code, and it is often unsafe to use the function twice within one expression.
    In this case it would be fine, were it not for the admonition to use malloc: the comment says "helper function for printRecord", so it is reasonable to suppose that the string will not be modified. Therefore, even with the use of a static local variable, the output of the function depends on the input, and not on any saved state that can vary from function call to function call.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 08-02-2013, 06:45 PM
  2. Replies: 5
    Last Post: 02-23-2013, 03:37 PM
  3. Classes Project (Not class project)
    By adam.morin in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2011, 01:48 AM
  4. Paid project - The Free Marketing Project
    By sharefree in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 10-27-2010, 02:15 PM
  5. your 11th & 12th grade c++ project or similar project
    By sleepyheadtony in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 01-13-2002, 05:14 PM