Questions tagged [file-pointer]

A pointer set to a file.

Files can be pointed to. These pointers are specific for files. In C for example, we have FILE which is used as file pointer (if followed by an asterisk *).

The file pointer points to a certain position of the file and can be moved in any location of the file desired.

161 questions
152
votes
9 answers

What's the difference between a file descriptor and a file pointer?

How are file descriptors and file pointers related? When is it appropriate to use each?
karthi_ms
  • 5,568
  • 11
  • 38
  • 39
46
votes
1 answer

ftell on a file descriptor?

Is there a way to do what ftell() does (return the current position in the file) on a raw file descriptor instead of a FILE*? I think there ought to be, since you can seek on a raw file descriptor using lseek(). I know I could use fdopen() to create…
HighCommander4
  • 50,428
  • 24
  • 122
  • 194
23
votes
6 answers

Using a C string like a FILE*

I have a C function that reads a stream of characters from a FILE*. How might I create a FILE* from a string in this situation? Edit: I think my original post may have been misleading. I want to create a FILE* from a literal string value, so that…
math4tots
  • 8,540
  • 14
  • 58
  • 95
13
votes
5 answers

Program doesn't wait for user input with scanf("%c",&yn);

This is the basic code to a program I am writing to practise using files in C. I am trying to detect whether the output file already exists and if it does exist I want to ask the user if they would like to overwrite it or not. This is the reason…
user1083734
  • 4,815
  • 8
  • 24
  • 24
13
votes
1 answer

Check if two file pointers point to same file in Python

How do I check if two file pointers point to the same file or not. >>> fp1 = open("/data/logs/perf.log", "r") >>> fp1 >>> fp2 = open("/data/logs/perf.log", "r") >>> fp2
Optimus Prime
  • 6,817
  • 5
  • 32
  • 60
12
votes
3 answers

How to find the current line position of file pointer in C?

How can I get the current line position of the file pointer?
En_t8
  • 7,595
  • 5
  • 20
  • 14
10
votes
3 answers

Opening a file in 'a+ 'mode

If a file is opened using the following command: FILE *f1=fopen("test.dat","a+"); The man page reads: a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file…
user191776
10
votes
1 answer

Is there no GetFilePointer(Ex) Windows API function?

I am trying to debug a program that manipulates a file. For example, I set the file-pointer to offset 4 (using a base of 0), but it seems to be starting at offset 5 instead. To try to figure out what is happening, I want to put in a line to print…
Synetech
  • 9,643
  • 9
  • 64
  • 96
7
votes
2 answers

Reading and writing binary files in C

These are 2 separate applications. In the first one, I tried to store employee details like name, age and salary in the binary file named emp.bin. In the second application, I tried to view the contents of the file but in place of the name, only…
0x5961736972
  • 148
  • 1
  • 7
5
votes
3 answers

What is difference between file descriptor and file pointer?

Possible Duplicate: What's the difference between a file descriptor and file pointer? If I open file like this: FILE *fp = fopen("mr32.txr","r"); then fp is file pointer or file descriptor? What is difference between them?
Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222
4
votes
2 answers

Obtain filename from file pointer in C

Possible Duplicate: Getting Filename from file descriptor in C How get fileName having FILE*? Is there any way where I can find the file_name from a file-pointer in C? fp = fopen(file,"r"); From fp, is it possible to get the file name which I…
Gaara
  • 161
  • 1
  • 2
  • 4
4
votes
2 answers

File pointer position in file handling

f=open("hello.txt","r+") f.read(5) f.write("op") f.close() the text file contains the following text: python my world heellll mine According to me after opening the file in r+ mode the file pointer is in beginning(0). After f.read(5) it will reach…
om bahetra
  • 41
  • 4
4
votes
2 answers

How to get 'print()', 'os.system()' and 'subprocess.run()' output to be displayed in both console and log file?

Initially, I've a simple program to print out the whole output to the console. Initial Code to display output in the console only import os, subprocess print("1. Before") os.system('ver') subprocess.run('whoami') …
user9013730
4
votes
4 answers

Does fscanf moves the passed file pointer ahead?

I saw this code somewhere: #include int main() { FILE * fp; char s[1024]; fp = fopen("file","r"); while( fscanf(fp, "%s", s ) != EOF ) { puts(s); } return 0; } I expected that this will keep on printing…
Amit Tomar
  • 4,800
  • 6
  • 50
  • 83
4
votes
2 answers

Using fread function: size to be read is greater than available for reading

I have a question: I am using fread to read a file. typedef struct { int ID1; int ID2; char string[256]; } Reg; Reg *A = (Reg*) malloc(sizeof(Reg)*size); size = FILESIZE/sizeof(Reg); fread (A, sizeof(Reg), size, FILEREAD); Using a…
richardaum
  • 6,651
  • 12
  • 48
  • 64
1
2 3
10 11