ProgrammingModerateProduct company OA
A file report.txt already exists and holds data. What does fopen("report.txt", "w") do?
- A. Opens it and positions writes after the existing data
- B. Opens it for reading only
- C. Opens it and truncates it to length zero, discarding the old contents
- D. Fails and returns NULL because the file already exists
Correct answer: C. Opens it and truncates it to length zero, discarding the old contents
Mode "w" creates the file or truncates an existing one. To keep the contents and add to the end, use "a"; to fail if the file exists, C11 offers "wx".
More C Programming questions
- The user types hello and presses Enter. After char buf[8]; fgets(buf, sizeof buf, stdin);, what does buf hold?
- The user types abcdefghij and presses Enter. What is strlen(buf) after char buf[8]; fgets(buf, sizeof buf, stdin);?
- After scanf("%d", &n); reads the input 42 followed by Enter, why does the next getchar() return 'n' instead of waiting for new input?
- What is printed? c int buf[4], head = 0, count = 0; for (int v = 1; v <= 6; v++) { buf[(head + count) % 4] = v; if (count < 4) count++…
- What is printed? c int st[10], top = -1; #define PUSH(x) (st[++top] = (x)) #define POP() (st[top--]) int main(void) { PUSH(3); PUSH(5)…
- A binary tree is stored with child indices (−1 for none). What does h(0) return? c int L[] = {1, 3, -1, -1, -1}, R[] = {2, 4, -1, -1, -1}…