The problem is that; when I'm trying to store some string containing pre-defined macros into a variable compiler is giving me an error
#include <stdio.h>
int main()
{
char string[100] = "This line is appended using C programe and,\nThe data is = %s and time is = %s.\n\n", __DATE__, __TIME__;
return 0;
}
And the error is
yyy.c: In function 'main':
yyy.c:5:111: error: expected identifier or '(' before string constant
char string[100] = "This line is appended using C programe and,\nThe data is = %s and time is = %s.\n\n", __DATE__, __TIME__;
^~~~~~~~
And when I'm trying with the below syntax
#include <stdio.h>
int main()
{
char string[100] = ("This line is appended using C programe and,\nThe data is = %s and time is = %s.\n\n", __DATE__, __TIME__);
return 0;
}
The error that occurred is
yyy.c: In function 'main':
yyy.c:5:24: error: invalid initializer
char string[100] = ("This line is appended using C programe and,\nThe data is = %s and time is = %s.\n\n", __DATE__, __TIME__);
^
but when I'm printing the same line with print statement i.e.
#include <stdio.h>
int main()
{
printf("This line is appended using C programe and,\nThe data is = %s and time is = %s.\n\n", __DATE__, __TIME__);
return 0;
}
There is no error and the output is
This line is appended using C programe and,
The data is = Jul 9 2021 and time is = 11:32:06.