prompt> cal 5 2001
and our friend, the computer shows us
May 2001
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
#include
int main()
{
system("cal");
return 0;
}
#include
int main()
{
int month,year;
char cmd[80];
printf("Give the month : "); scanf("%d", &month);
printf("Give the year : "); scanf("%d", &year);
sprintf(cmd,"cal %d %d", month, year);
system(cmd);
return 0;
}
#include
int main()
{
int month,year,day;
char cmd[80];
char tmpfile[80];
char line[80];
FILE *fp;
printf("Give the month : "); scanf("%d", &month);
printf("Give the year : "); scanf("%d", &year);
tmpnam(tmpfile);
sprintf(cmd,"cal %d %d > %s", month, year, tmpfile);
system(cmd);
fp = fopen(tmpfile,"r");
fscanf(fp," %[^\n]", line);
printf("Number of days in %s : ", line);
fscanf(fp,"\n%*[^\n]\n"); /* skip banner lines */
while (fscanf(fp,"%d",&day) == 1); /* skip days */
printf("%d\n", day);
remove(tmpfile);
return 0;
}
int depth()
{
char tmpfile[80];
char cmd[80];
char path[80];
int i,cnt = 0;
FILE *fp;
tmpnam(tmpfile);
sprintf(cmd,"pwd > %s",tmpfile);
system(cmd);
fp = fopen(tmpfile,"r");
fscanf(fp,"%s",path);
for (i = 0; path[i] != '\0'; i++)
if (path[i] == '/') cnt++;
fclose(fp);
remove(tmpfile);
return cnt;
}
int depth()
{
char *path;
int i,cnt=0;
path = (char*)getenv("PWD");
for (i = 0; path[i] != '\0'; i++)
if (path[i] == '/') cnt++;
return cnt;
}
A: C
@echo 1
B:
@echo 2
C: B
@echo 3
Give the sequence of numbers displayed when the user types
2
3
1
2
2
3
FINAL EXAM in LC C3 on Monday 30 April 2001 at 1:00-3:00PM.