file-handling is an abstraction of common actions such as creating, opening, closing, reading, updating, writing, comparing and deleting files
Questions tagged [file-handling]
2915 questions
0
votes
2 answers
Why does the program print only the last line of the file, even after reading the entire file?
I want to write a program in C which just reads a file, stores it into an array and then prints the array. Everything works fine but when the text file has more than one line, I always just get the last line printed out.
This is my Code:
#include…

chrizzla
- 53
- 8
0
votes
0 answers
Reading whole file into a Buffer
I am trying to read a RSA key file into a buffer with the code below
char* readkeyBuffer(){
char *buffer;
long length;
FILE *f;
f= fopen ("file.p12", "rb");
if (f)
{
fseek (f, 0, SEEK_END);
length = ftell (f);
…

Shinu S
- 47
- 5
0
votes
0 answers
Segmentation fault error in copying array In C
#include
#include
typedef struct monster {
int id;
char name[64];
char element[64];
int population;
double weight;
} monster;
typedef struct {
long long int compares;
long long int copies;
}…

Deepak Sharma
- 53
- 7
0
votes
2 answers
I cannot add list into text files
Code
file=open(r"C:\Users\Owner\Documents\Python\Apparel store\Python\Practical File\File Handling\student.txt","w")
n=1
while n=="1":
l=[]
rollno=int(input("Enter rollno:"))
l.append(rollno)
name=input("Enter name:")
…

I appreciate your help
- 33
- 1
- 8
0
votes
2 answers
Deleting a specific key from a file using file I/O in C++
string _delete_an_apiKey(int n)
{
string a;
string del;
int cnt = 0;
ofstream f1("tempAPIKeys.dat",ios::app); // Temporary file for executing deletion
ifstream f2(file,ios::in); // Main file containing all…

GhostVaibhav
- 72
- 7
0
votes
2 answers
c++ file handling, reading within a file
Good day, I am struggling to read a file from a .txt document, any help would be appreciated.
The code is almost done, it runs without errors, but it wont read the file where the data is stored.
the data is stored under the document:…

user13784854
- 19
- 3
0
votes
3 answers
Printing common rows from multiple files
I have 3 files that contain some arbitrary number of rows (specified in the first line). I want to get all the common rows in those files. For example, in every file, I have a number of rows the file contains and each line contains four…

Akash Tadwai
- 100
- 1
- 9
0
votes
1 answer
Trying to open and read files with fstream and sstream
#include
#include
#include
#include
int main()
{
const char* path = "C:\Dev\devAstroides\printFileToScreen\Hello.txt";
std::string Code;
std::ifstream File;
…

Q broms
- 1
- 1
- 2
0
votes
0 answers
how to write a string which is in a variable in a txt file
I have a variable which contains a string that I want to write in a .txt file using python. But I don't know how to do so. e1 is the variable which contains the string.
from tkinter import *
root = Tk()
root.title("records…

Akki Maharaj
- 9
- 1
0
votes
0 answers
a file handling cpp program compiles successfully but after sometime it gives unprecedented output and stop running
'a program that will calculate numerical and letter grades for a student and output a report from given txt file to the program.'
student.txt file is
a b 3 100 100 100 0.15 3 75 80 90 0.40 3 60 70 70 0.45
c d 4 100 88 100 92 0.15 3 75 80 90 0.40 2…

B G
- 29
- 5
0
votes
2 answers
Facing problem to append text into a (file.txt) file in python
How to append text into a (file.txt) file in python
Here is my program code:
file = open("file.txt", "a")
aa = 10
bb = 1
cc = 12
xx = 20
try:
if xx > aa:
file.write("Yes xx is greater than aa")
file.close()
elif xx < aa:
…

ammely
- 85
- 1
- 8
0
votes
2 answers
Using Netbeans writing to a csv file not working
I am currently working on a vehicular cloud program that takes client information and takes vehicle owner information and stores them in separate .csv files. I am using an array to separate each object making it easier to put in the csv file but…

Jualston
- 37
- 6
0
votes
1 answer
writing and reading for file
i'm a newbie on c and i want to check if i have understood how funtions for file handling does work, here is my code. the issue that i faced is the evaluation of fx in every x is stored successfully on the file pointinterpol.dat, but when i want to…
user14356872
0
votes
0 answers
How to copy the source code of my website recursively into a zip file and download using PHP
Since my file manager doesn't allow me to download multiple files, instead only allowing me to download them one by one (which is tedious, and, eventually will become inefficient), I want to know how to download all my website file contents into a…

Reality
- 637
- 1
- 6
- 25
0
votes
0 answers
How to deal with UnicodeDecodeError while reading a file?
SNIPPET:
with open("sample.txt", 'r') as f:
filedata = f.read()
ERROR that I get:
UnicodeDecodeError Traceback (most recent call last)
in
1 `with open("sample.txt", 'r') as f:`
----> 2 filedata =…