Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a.Write the definition of a function named readDate with one parameter, a pointe

ID: 3597279 • Letter: A

Question

a.Write the definition of a function named readDate with one parameter, a pointer to a struct date value (see below). There is no return value.
The struct date definition is:
struct date {
  char month[4]; /* three-character month abbrev */
  int day;
  int year;
};
(This definition is already provided. DO NOT include it in your solution.)
The function reads a date from standard input, using the following format: MMM DD, YYYY. It fills in the fields of the struct pointed to by the parameter. Assume that the month string is 3 characters or less, and that the day and year are both decimal integers.

b. Write a statement that reads two integers from the file referenced by fp, and stores them in integer variables x and y, in that order. Don't be concerned about reaching the end of file.

Explanation / Answer

a)

void readDate(struct date *d) {
scanf("%s %d, %d", &(d->month), &(d->day), &(d->year));
}

full code for demo

#include <stdio.h>

struct date {
char month[4]; /* three-character month abbrev */
int day;
int year;
};

void readDate(struct date *d) {
scanf("%s%d%d", &(d->month), &(d->day), &(d->year));
}

int main()
{
struct date d;// = (struct date *)malloc(;
readDate(&d);
printf("%s %d %d ", d.month, d.day, d.year);
return 0;
}

sample run

jan 20 1178
jan 20 1178

b)

fscanf(fp, "%d%d", &x, &y);