This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>To: address@hidden
>From: Igor Pesenson <address@hidden>
>Subject: Re: 20030203: subject
>Organization: Lawrence Berkeley National Laboratory
>Keywords: 200302031956.h13Ju0623075
Igor,
> ... I failed to clearly specify that the problem I'm
> having is not placing a string, ie "12-Nov-2002, 0:00:00 GMT", but having 
> that string be a
> variable. I can hardcode the variable as in
>   stat = nc_put_att_text(ncid, base_time_id, "string", 23, 
> "12-Nov-2002,0:00:00 GMT");
> but I can't seem to do
>   strcpy(date_str, "12-Nov-2002,0:00:00 GMT");
>   stat = nc_put_att_text(ncid, base_time_id, "string", 23,&date_str);
Oops, I didn't see it the first time, but you should use just
"date_str" instead of "&date_str" as the last argument in the
nc_put_att_text() call:
   stat = nc_put_att_text(ncid, base_time_id, "string", 23, date_str);
assuming date_str is declared as either an array of char
   char date_str[100];
or as a pointer to char for which you allocate space
   char *date_str = malloc(sizeof char, strlen("12-Nov-2002,0:00:00 GMT"));
In either case, date_str is already an address of a string, so you
don't need to take the address of it again.  With "&date_str" you are
saying the string is located at the address of the pointer rather than
at the address of the string it is pointing to.
--Russ
_____________________________________________________________________
Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu