0

Please help me with this question. What would be the output? Thanks in advance.

Assuming that the content of the file “test.txt” is The end sem starts here what is the output of this program? int main() { FILE *fp; char c[1024]; fp = fopen("test.txt", "r"); c[0] = getc(fp); fseek(fp, 0, SEEK_END); fseek(fp, -4, SEEK_CUR); c[1]=getc(fp); fseek(fp, 2, SEEK_CUR); c[2]= getc(fp); c[3]=’\0’; printf(“%s”,c); return 0; } Options: A. Thr B. Te C. her D. sem

26th Jun 2020, 2:56 PM
O.Naga Lakshmi Lalasa
O.Naga Lakshmi Lalasa - avatar
3 Antworten
0
(A) Thr 1. c[0] stores 'T' ie the first character of the file 2. SEEK_END takes you to the end of file 3. The pointer moves backwards by 4 characters to 'h'. Hence, c[1] = 'h' (forth character from the end) 4. Then seek forward 2 characters to 'r' => c[2] = 'r' 5. Finally c[3] = null to mark end of string
26th Jun 2020, 3:25 PM
Abhishek Tandon
Abhishek Tandon - avatar
+ 1
Thank you so much Infinity and uday kiran
27th Jun 2020, 8:06 AM
O.Naga Lakshmi Lalasa
O.Naga Lakshmi Lalasa - avatar
0
1. Initially fp points to first character in the file ,so c[0] = 'T' 2. fseek function is used to move the position of the pointer . SEEK_END place the pointer beyond the last character. 3.SEEK_CUR moves the pointer by no.of bytes from it's position. c[1] = 'h' c[2] = 'r' c = "Thr"
26th Jun 2020, 3:51 PM
uday kiran
uday kiran - avatar