Here's some code that will do what you want:

#include <stdio.h>
#include <string.h>

char **str_fcn();

void
main()
{
  int i;
  char **sa;

  sa = str_fcn();
  for (i=0; i<12; i++) {
    fprintf(stdout, "sa[%d]: %s\n", i, sa[i]);
  }
}

char **
str_fcn()
{
  char **str_array;

  str_array = (char **)calloc(sizeof(char *), 12);

  str_array[0] = strdup("Jan");
  str_array[1] = strdup("Feb");
  str_array[2] = strdup("Mar");
  str_array[3] = strdup("April");
  str_array[4] = strdup("May");
  str_array[5] = strdup("June");
  str_array[6] = strdup("July");
  str_array[7] = strdup("Aug");
  str_array[8] = strdup("Sept");
  str_array[9] = strdup("Oct");
  str_array[10] = strdup("Nov");
  str_array[11] = strdup("Dec");

  return str_array;
}

This is the general idea -- you should be able to do what you want from
this.

Regards,
-A.


Glynn Clements wrote:
> 
> Subject: Message not reaching listserv
> Date: Wed, 24 Jun 1998 22:04:47 -0400 (EDT)
> From: Joseph Martin <[EMAIL PROTECTED]>
> To: Glynn Clements <[EMAIL PROTECTED]>
> 
> Hello,
>         I am a subscribee to the linux-c-programming listserv. I have
> tried to send the message there several times during the last few days
> with no luck. It's not getting bounced, but I'm not recieving it back in
> my mailbox either. Could you please post it for me? (Any maybe answer too?
> :)
> 
> -=-=-=-==-=-=-=-=-=-=-=-==-=-=-=-==-=-=-=-=-=-==-=-=-==-=-=-=-=-=-=-=
> >From [EMAIL PROTECTED] Tue Jun 23 21:22:59 1998
> Date: Tue, 23 Jun 1998 21:18:07 -0400 (EDT)
> From: Joseph Martin <[EMAIL PROTECTED]>
> To: Linux C Programming <[EMAIL PROTECTED]>
> Subject: Help with strings, pointers, returns, etc
> 
> Hello,
>         I am struggling with my long time nemesis again - strings in C. I
> have a function I'm writing that will read in a file, assign each line to
> a subscript in an array, and return the array. Problem is I can't get pass
> the returning. Suggestions welcome. Code follows. Thanks a ton.
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include "file.h"
> 
> char *read_file()
> {
>         char line[10][80];
>         int i;
>         FILE *budget;
> 
>         if((budget = fopen("/home/martinja/.bashrc", "r"))==NULL) {
>                 printf("Cannot open config file\n");
>                 exit(1);
>         }
>         for(i=0; i<10; i++) {
>                 fgets(line[i], 80, budget);
>                 printf("%s", line[i]); // This tests if line reads
>                                         // correctly
>         }
>         fclose(budget);
>         return ??? //help here please!
> }
> 
> Joseph Martin
> [EMAIL PROTECTED]
> Linux newbie/sysadmin ( dangerous combo! ;-> )
> 
> B.T.W. The include file "file.h" just has the declaration for "read_file".

-- 
Aaron J. Marks                 Communications and Computing Systems Lab
Assoc. Member Tech Staff       Advanced Networks and Computation Group
[EMAIL PROTECTED]             Sarnoff Corporation

Reply via email to