Here is a sample exam. What other kinds of questions do you think I could prepare before walking in there since all resources are permitted?

Write a single program which contains functions to do the following steps. Each of these
steps involve reading the file above and displaying some of its content in some form. Your
solution may use more functions than this to remove duplicate code where necessary.
1) Write a function that can display the contents of each line on the screen.
2) Write a function that outputs the 3rd line only.
3) Write a function that can display the contents of each line on the screen in reverse order.
4) Write a function that will output the 5th line only, with the characters reversed.
5) Write a function that will count how many words there are in the file and output the total

Dani AI

Generated

Short answer: stop trying to guess exact questions and instead master the small set of C idioms you'll need to implement the sample tasks quickly and correctly. For the file/line/word problems you posted, focus on reliable line I/O, safe string handling, simple in-place algorithms (reverse a buffer), and robust edge-case handling. is right that inventing random exam questions is low value; targeted drills and a few proven templates are what actually saves time during an open-book, time‑limited test.

Practice the concrete topics below and have tiny, tested snippets ready to drop into your solution:

  • File I/O patterns: fopen/fclose, fgets/fgetc, getline (if available), fseek/ftell, check for NULL/EOF.
  • Line processing: detect/remove trailing newline, handle CRLF, long lines that exceed your buffer.
  • String ops and safety: strlen, memmove, strncpy/strdup alternatives, avoid gets, check buffer bounds.
  • Tokenization/word counting: isspace, strtok or manual scanning to count words robustly (handle tabs/multiple spaces).
  • Memory: malloc/realloc/free patterns and ownership rules; prefer streaming solutions for big files.
  • Edge cases: empty files, fewer than N lines, very long single line, non-ASCII/UTF-8 caveats for "reverse characters".

A tiny helper you’ll use a lot — reverse a C string in place and strip a trailing newline:

void reverse_inplace(char *s) {
    if (!s) return;
    size_t len = strlen(s);
    if (len && s[len-1] == '\n') s[--len] = '\0';
    size_t i = 0, j = (len ? len - 1 : 0);
    while (i < j) { char t = s[i]; s[i++] = s[j]; s[j--] = t; }
}

Final tips: make a one-page "template sheet" with exact prototypes and common idioms, pre-test those templates on the edge cases above, compile with warnings (e.g. -Wall -Wextra) and run simple manual tests. In the exam, read the spec carefully, write small helper functions, test mentally or with quick prints, and prefer correctness and clear error handling over clever micro-optimizations.

Recommended Answers

All 3 Replies

Are you creating the exam or taking it?

Taking it of course!

I asked because inventing questions for an exam that you're going to take is absolutely nonsensical; the questions you come up with are extremely unlikely to be on the exam. It's also open book, so aside from knowing enough of the material to find details in your references, I fail to see how thinking up an unrelated practice exam could possibly improve your chances of passing the actual exam.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.