1
struct s
{
    char date[100];

}su;

char *formateddate()
{
   static char result[100];
   time_t t;
   t = time(NULL);
   strftime(result, sizeof(result), "%Y-%m-%d", localtime(&t));
   return result;
}



void main()
{
    char *currentDate=formateddate();
    printf("%s",currentDate);
    //su.date=currentDate;

}

Error: assignment to expression with array type.

I am trying to return current date and store it to the su.date .How can i store it and use further ?

davidlowryduda
  • 2,404
  • 1
  • 25
  • 29
PublisherName
  • 121
  • 1
  • 2
  • 12

2 Answers2

1

You should use strcopy to copy into the array.

strcopy(su.date, currentDate);
davidlowryduda
  • 2,404
  • 1
  • 25
  • 29
0

Use strcpy(su.date, currentDate) instead of assignment, or probably better pass su.date as argument to formatteddate().

mrtnlrsn
  • 1,105
  • 11
  • 19