162 questions
1
vote
1
answer
410
views
Python Seek Function with an offset exceeding the file size
I am trying to understand how the seek function in python file handling works. The syntax of this function is seek(offset, whence). The parameter 'whence' is like a point of reference with possible ...
2
votes
0
answers
44
views
Can I rightfully name my opened file a stream if at some point I move its file-pointer backward?
Quoting from https://learn.microsoft.com/en-us/cpp/c-runtime-library/files-and-streams?view=msvc-170
Before you can perform many of the operations on a file, the file must be opened. Opening a file ...
0
votes
1
answer
28
views
File pointer postion
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 ...
0
votes
0
answers
38
views
I have got struck in a problem where I have the task to update the old line with a new line in a .txt file using C
I have opened the file in "r+" mode and tried to use fputs to replace old_line (line) with new_line (updated_line)
char updated_line[] = "Hello This was ABCD";
fseek(fp, -(strlen(...
1
vote
0
answers
45
views
Where are text files in my Xcode project? [duplicate]
I've created a simple program to write in a text file, and it seems as if it works. I just cannot find where to locate the text file it created in my Xcode project.
FILE *fptr;
fptr= fopen(&...
0
votes
1
answer
165
views
pointer in binary files after using fread command
im learning at the moment about file pointers,and came across this code which was given as exemple
i tried replicating it in visual studio but i keep getting run time errors that are not relevent at ...
0
votes
0
answers
20
views
declaring file pointer in main() and using it in multiple functions while the file is opened [duplicate]
So basically i need to declare file pointer in main functions, and use it in multiple sub-functions, file will be opened in sub function.
int main(){
FILE *filepointer;
...
2
votes
2
answers
489
views
Not being printed out when using fgets
I'm learning about file input/output in C. But there is something I don't understand.
I was about to print the simple sentence in the [words.txt] using fgets, but it doesn't work.
[words.txt] as below:...
1
vote
1
answer
72
views
Why do I get FILE pointer error while checking NULL condition?
#include<stdio.h>
#include <string.h>
#include <windows.h>
#define PATH "F:\\c\\projects\\Banking Management System\\data\\"
#define F_PWD "pwd.txt"
#define ...
0
votes
1
answer
2k
views
Loop through data stored in buffer in C
I have a .dat file with two columns, time & channel of audio data. I am trying to just read the column channel, write it in a different .dat file and save it.
In the code, I have stored the file ...
0
votes
1
answer
396
views
C Reading records from text file in C using structure
I am trying to extract records from a text file named lib.txt. My program is a very simple library based management program where I will have to print all books by a given publisher or department.
My ...
0
votes
1
answer
725
views
C fwrite char array
This is a function that use a set of predefined code to encode input file (infp) to output file (outfp) (in normal text mode)
void encode( char *codes[], FILE *infp, FILE *outfp) {
while (infp) {
...
1
vote
1
answer
585
views
std::filebuf passed to std::ifstream not always called
The Goal
Have unbuffered I/O and disabled kernel page cache for a legacy C++11 program. This feature must be on demand (through an executable parameter). The idea is to reduce the memory overhead of I/...
0
votes
0
answers
21
views
fgets statement reads first line and not sure how to modify because I have to return a pointer [duplicate]
I am a bit confused about how to modify my code to return a buffer that stores multiple lines of a file as a string and not just the first line.
char * readFile ( char * filename){
char text[500];
...
0
votes
1
answer
362
views
PHP. How to read a file, if it is writing without a problem with "a+", but is not readable with "r"?
I have two scripts: one of them writes the value of a variable to a file. In another script, I try to read it. It is written without problems, but it is not readable.
Here I write to a file:
$peer_id=...
0
votes
1
answer
48
views
C depth-first-search - how to handle not enough file pointers being available?
If I am recursively searching directories and entering all sub-directories, how can I handle not depth exceeding not enough file pointers being available and exit the program (without segmentation ...
1
vote
2
answers
466
views
Why does seekp() fail in this case?
I am using this program to modify every vowel in text.txt to become the hashtag ('#')
#include <fstream>
#include <iostream>
int main()
{
std::fstream iofile{ "text.txt", ...
0
votes
0
answers
388
views
Is there any way to safely and successfully write to a hand-picked file descriptor number, other than FD=0,1,2? [duplicate]
My overall objective (motivation for the question):
To provide an executable ìo, from C/C++ compilation/linking, so that a user can execute it alternatively as:
io 3> myout.txt.
In this case myout....
0
votes
1
answer
964
views
function to print the contents of a text file
here's the code i wrote:
#include <stdio.h>
#include <stdlib.h>
void Print_File(FILE *f)
{
fopen("f", "r");
char s = fgetc(f);
while (s != EOF)
{
printf("%c", s);...
1
vote
2
answers
1k
views
For a file pointer in C, how to measure the distance between the current position to the end of file?
For a given file pointer (FILE *), is it possible to rapidly determine the distance from current position to the end of file.
The time it takes to figure out the actual distance should be not ...
0
votes
0
answers
175
views
How do I get the file pointer that is being referenced by a file descriptor?
I am trying to use dup2 to communicate between parent and child in the following code.
#include <stdio.h>
#include <unistd.h>
void main(int argv, char *argc) {
int testpipe[2];
...
0
votes
1
answer
646
views
TCL file parsing (Loop to read subsequent lines once pattern found)?
Below is a sequence that is repeated multiple times in the file that I will be reading using TCL.
Startpoint: FF1 (rising edge-triggered flip-flop clocked by Clk)
Endpoint: FF2 (rising edge-triggered ...
1
vote
0
answers
60
views
How can i find specific char in file with file_pointer?
I want to make simple login,register system. and register part is done, but login part is little confuse..
Login with Txt file. Filename - ID, file including "Nickname|PW"
then scanf ID first, if id ...
1
vote
0
answers
85
views
ftell returns 11 instead of 10
I have a file test.txt, which contains two lines.
123456789
abcdefghi
And here is a C code.
FILE* fp;
char str[20];
fp = fopen("test.txt", "r");
printf("%d", ftell(fp)); // 0
...
-2
votes
1
answer
130
views
C++ Reading fstream data from a file does not return correct values. inputFile.tellg returns -1
I am trying to read data from an input file that contains an integer on the first line ( represents the number of images listed in the file ), a float on the second line( this is used for other ...