• reopened by
1,766 views
1 1 vote

I'm trying to use the fseek() and ftell() function to find the length of the file 'test.txt' which is present in the same directory as the file 'file.c'.


file.c

#include <stdio.h>

int main()
{
    FILE *fp;
    int len;
    fp = fopen("test.txt", "r");

    if(fp == NULL)
    printf("Error opening file.");

    fseek(fp, 0, SEEK_END);
    len = ftell(fp);
    fclose(fp);
    printf("The size of the file test.txt is: %d.\n", len);

    return 0;  
}


test.txt

abc def


There is no problem when I compile the file, but when I try to run it, I'm getting the 'Segmentation fault (core dumped)' error abd the execution terminates.

What's going wrong in here?

1 Answer

Position:
Show:

Related questions

0 0 votes
0 0 answers
643
643 views
ykrishnay asked May 20, 2022
643 views
What is stream in c programming ? as i read file io in c programming so thats where i read “stream” word so what stream means ? thank you
1 1 vote
1 answers 1 answer
2.4k
2.4k views
iarnav asked Apr 11, 2017
2,368 views
Hello, please kindly list out the topics which are needed to be studied from topic file system?!You can also pinpoint the topics from Galvin book 7th edition.
0 0 votes
1 1 answer
786
786 views
agoh asked Dec 13, 2016
786 views
Given disk block size, disk block address size, number of direct and single, double, triple indirect blocks.n = ( No of direct addresses + (db size/dba) + (db size/dba)*(...
1 1 vote
1 answers 1 answer
2.9k
2.9k views
Don't you worry asked Jun 3, 2016
2,937 views
A. File structureB. RecordsC. FieldsD. Database