C Programming - Input / Output - Discussion

3. 

Point out the error in the program?

#include<stdio.h>

int main()
{
    FILE *fp;
    fp=fopen("trial", "r");
    fseek(fp, "20", SEEK_SET);
    fclose(fp);
    return 0;
}

[A]. Error: unrecognised Keyword SEEK_SET
[B]. Error: fseek() long offset value
[C]. No error
[D]. None of above

Answer: Option B

Explanation:

Instead of "20" use 20L since fseek() need a long offset value.

Kunal said: (Sep 29, 2011)  
What is the use of fseek() ?

Babita said: (Apr 18, 2012)  
fseek()
It seeks a specified place within a file and modify it

Tanya said: (Jul 14, 2013)  
What is seek_set() ?

Divya said: (Jul 30, 2013)  
Is extension of the file "trial" necessary?

Prashant said: (Sep 20, 2013)  
What is seek_set()? can anyone explain.

Ravi Sankar said: (Jan 28, 2014)  
seek_set = Cursor moves to first letter of the file .
seek_end = Cursor moves to last letter of the file.
seek_cur = Cursor starts when ever we accessed last world.

Kirubashini said: (Dec 30, 2015)  
I don't understand this line:

fseek(fp, "20", SEEK_SET);

Please explain me.

Madhu said: (Aug 10, 2017)  
I can't understand. Please explain this program.

Pavani said: (Sep 14, 2017)  
What is mean by fseek?

Nitesh said: (Oct 9, 2017)  
Please explain the program.

Compeq said: (Apr 22, 2018)  
fseek(fp, "20", SEEK_SET);

The correct answer should be: Invalid conversion from const char* to long int.

Vishal Babasaheb Rahikar said: (Jul 22, 2018)  
Syntax for feel is;

fseek(file*stream,long offset value,int whence);
Here while providing offset value provide as 20L not 20 ,3rd argument have 3 macros SEEK_SET,SEEK_CUR,SEEK_END.

SEEK_SET means character seeking starts from the beginning of file, SEEK_CUR means starts seeking from last accessed word and SEEK_END means starts from end towards the beginning.

G.Sai Nikhitha said: (Mar 13, 2020)  
What is the meaning of
fseek(fp,-2,SEEK_CUR);

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.