Function that returns string from a sub function to the main function

Discussion in 'Embedded Systems and Microcontrollers' started by Dumken, Aug 5, 2015.

  1. Dumken

    Thread Starter New Member

    Oct 7, 2014
    Hi guys. Can u pls help me with a mikroc code that will return a group of string to the main function.
    Code (Text):
    1. if(weekdays==1)
    2. {
    3. char days[]="sunday';
    4. return days;
    6. }
    pls help me with the code that will return that. even if it requires pointers
  2. Papabravo


    Feb 24, 2006
    What you are trying to do makes no sense. If you define a string as an array of char inside a function, the storage for that string is allocated on a stack frame. When you return from the function the stack frame disappears or can get overwritten and your pointer to the string will now point to something which may or may not contain the string. A function can return a pointer to a string, but that string has to be located in a place that is no local to the function.
  3. Dumken

    Thread Starter New Member

    Oct 7, 2014
    Actually what i want to do is to use those string values to form dot matrix display where it would be selected individually from the array of binary numbers that forms the character. Pls do you know how i can achieve such.. The display is for calender that shows something like this "MON 03 AUG"
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    It is a multi step process.

    You have a number for a day. The array below will pass you a char array reference (pointer) to the 3 letter ASCII string for that day.

    Similarly you have a number for a month. The array below will pass you a char array reference (pointer) to the 3 letter ASCII string for that month.

    Now comes a little tricky part. You need to convert letters into pixels or dots. This takes a two-dimensional array of data, one dimension for the letter and the other dimension for the column.

    Here at the arrays:
    Code (Text):
    1. static char *DAY_OF_WEEK[] = {"XXX", "SUN", "MON", "TUE",
    2.                               "WED", "THU", "FRI", "SAT"];
    4. static char *MONTH[] = {"XXX", "JAN", "FEB", "MAR", "APR", "MAY",
    5.                         "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
    7. static char *DOT_INFO[3][5]=
    8.   {0H00, 0H02, 0H04, 0H08, 0H10, 0H20},  // \
    9.   {0H00, 0H20, 0H10, 0H08, 0H04, 0H02};  // /
    10.   {0H00, 0H22, 0H14, 0H08, 0H14, 0H22};  // X
    The DOT_INFO is just for reference now. I assumed you have a 7 row 5 column display and are using the pixel data to drive the rows. The data (may be correct don’t take it as sooth) is to draw a back slash, forward slash, and an X.

    Do note the code for the slashes and the X are 0, 1, and 2. That is NOT the ASCII values for these. You will have to do some finagling to make a DOT_INFO array that starts at zero. I would think of making the numbers in slots 0-9 and the letters above.

    Also remember you need lots of data to store the DOT_INFO array. As I have it for the 5x7 this takes 180 bytes of storage. Since it is a static array it should be in program memory (assuming a PIC) but make sure you don’t run out.

    That barely scratches the surface. I know some more but don’t have time to type it all out this morning. (Sunday I fly cross county so will have the time but limited resources and may not have the inclination).
    Dumken likes this.