>>I am forced to work on a Non-ANSI compliant compiler (1988)
Okay, I can't guarantee that this will work for you. I assume that you have to use K&R C which I'm not terribly familiar with and that your stdio.h header has popen(), FILE *'s, fgets(), and pclose(). Also, if you have strrchr() in string.h then replace the one I rolled for you :-) If you don't have fgets() then you should have gets(), if you don't have popen() then the only other thing I can think of is to redirect the date command to your program and use it like this
Code:
int main()
{
char temp[100];
/* Input directed from 'date' */
fgets(temp, sizeof temp, stdin);
printf("The current year is -- %s", parse(temp));
return 0;
}
Anyway, here's the other one :-)
Code:
#include <stdio.h>
/* date format UNIX command: Wed Jan 29 12:00:02 CST 2003 */
#define DELIM ' '
char *strrchr(s, c)
char *s;
int c;
{
char *sc;
for (sc = 0; ; s++)
{
if (*s == c)
{
sc = s;
}
if (*s == '\0')
{
return sc;
}
}
}
char *parse(s)
char *s;
{
return strrchr(s, DELIM) + 1;
}
int main()
{
char temp[100];
FILE *pipe = popen("date", "r");
fgets(temp, sizeof temp, pipe);
printf("The current year is -- %s", parse(temp));
pclose(pipe);
return 0;
}