Skip to main content

Questions tagged [file]

A block of arbitrary information, or resource for storing information, accessible by the string-based name or path. Files are available to computer programs and are usually based on some kind of persistent storage.

Filter by
Sorted by
Tagged with
45 votes
5 answers
10k views

Writing computer generated music to a .wav file in C

See the next iteration. I wrote this simple C program for writing computer generated music to a WAV file over three years ago. I refactored it a little, but it does not look good to me. Any ...
coderodde's user avatar
  • 29.1k
26 votes
4 answers
3k views

Convert Bitmap Font to Texture Atlas

I wanted to render the textures that comprise a bitmap font glyph onto the screen directly as an Image in libGDX. When you make a bitmap font using a program (such ...
bazola's user avatar
  • 8,569
26 votes
6 answers
215k views

Fast way of searching for a string in a text file

I have written this code to search for a string in a .txt file. Is it possible to optimize the code so that it searches for the string in fastest manner possible? ...
Allen Savio's user avatar
26 votes
2 answers
1k views

Please Save My Name

I wanted to create a save game system for my city building game that did not require the player to input a name for the city. It was also important to allow infinite save games, so I could not just ...
bazola's user avatar
  • 8,569
24 votes
4 answers
3k views

Perl CGI script to serve a PDF file

In a different post I showed the following Perl CGI script. Someone in the comments said that "You're using a lot of very unperlish syntax, and I'd like to give you some feedback". So, here it ...
amblabs's user avatar
  • 341
24 votes
1 answer
672 views

Wanted a cat. Got lolcat

Wanna learn Rust? Ya rly! I can haz FizzBuzz? No wai! Gimme /bin/cat then. But rustc say LOL! Must handle teh err0rz! Now iz ...
200_success's user avatar
22 votes
6 answers
4k views

Transcode UCS-4BE to UTF-8

Below is my entire program. You can read what it does thanks to the comments and specifications in particular. My question is: can it be improved? Would it be possible, for example, to avoid writing a ...
Alberto Ursino's user avatar
19 votes
6 answers
8k views

Explicit song lyrics checker

To stay in practice with my Python I've decided to write an explicit song checker. It checks each word in the song against an array of 14 explicit words contained in the text file. I've decided not to ...
Linny's user avatar
  • 10.3k
17 votes
3 answers
2k views

92 Spoons AI, sort of an AI in C++

I have made an AI that takes a user input and returns a predefined value. It that stores its info in a file (with the name of the file "default.92ai"). I thought ...
gsquaredxc's user avatar
16 votes
2 answers
43k views

Read and write BMP file in C

I'm teaching myself a little C, and I've found this website. It has an exercise about manipulating a BMP file in C. I would like to know if I can make my code look more "idiomatic" or professional, ...
Camilo's user avatar
  • 263
15 votes
2 answers
1k views

Can I buff up your file?

Here I have a method for reading the contents of a file into a buffer and returning whether or not it is successful. Here is what I would like reviewed: Speed: Am I reading in the file as fast as ...
syb0rg's user avatar
  • 21.8k
15 votes
4 answers
21k views

Read file into vector<byte>

I need to read a range of bytes from a file and return it as a std::vector<std::byte>. My current code looks like this: ...
Zitrax's user avatar
  • 271
15 votes
2 answers
29k views

Guessing a file type based on its content

In a project I'm working on, I need a component that is able to make a best guess about file's type based on its contents (a Stream). It doesn't need to do a ...
RobH's user avatar
  • 17k
14 votes
6 answers
1k views

What's in your file?

Another more simple project from my CS1 class that I didn't upload while I was sick last week: Write a program that computes all of the following statistics for a file and outputs the statistics ...
syb0rg's user avatar
  • 21.8k
14 votes
4 answers
104k views

Count number of words in a text file

Is this a good approach or is there some other solution that I am not aware of? ...
Deepak Singh's user avatar
14 votes
4 answers
3k views

Reading a DHT11 to a file

Disclaimer: not a Pythonista, first actual Python programme written right here. I'm reading a DHT11 sensor from GPIO pin 4 on my Raspberry Pi (thanks Thomas Ward for sending the RPi to me), and I ...
Der Kommissar's user avatar
14 votes
2 answers
313 views

Executing a program with a temporary directory and measuring the running time

I need a code review for best practices and code correctness of the following piece of code. run executes a program and validates in output. If the output is valid ...
Alexandru's user avatar
  • 409
14 votes
3 answers
691 views

Extracting a set of numbers from a file

I do most of my programming in C/C++ and Perl, but I currently learning Fortran. I began by coding up a simple program, something that took me < 5 minutes in Perl (see this thread from BioStar). ...
Daniel Standage's user avatar
14 votes
2 answers
52k views

Merging multiple JSON files using Python

I have multiple (1000+) JSON files each of which contain a JSON array. I want to merge all these files into a single file. I came up with the following, which reads each of those files and creates a ...
Alagappan Ramu's user avatar
13 votes
2 answers
5k views

Average spam confidence

Exercise 7.2 from Python for Informatics: Write a program to prompt for a file name, and then read through the file and look for lines of the form: ...
Mast's user avatar
  • 13.4k
13 votes
3 answers
2k views

Counting words / lines in Ruby

I solved this problem in Ruby: Write an utility that takes 3 command-line parameters P1, P2 and P3. P3 is OPTIONAL (see below) P1 is always a file path/name. P2 can take the values: “...
Sebastian N.'s user avatar
12 votes
2 answers
998 views

Speech Recognition Part 1: Generate Training Data

You've all heard of neural nets, no? One of the "hello world"s of neural nets is OCR with the MNIST dataset. My idea for speech recognition is to train the neural net with short labeled spectrograms ...
syb0rg's user avatar
  • 21.8k
12 votes
2 answers
902 views

A minimal CLI password storage and retrieval manager

Its primary function is to retrieve+copy a PW to your clipboard. It'll also add, update, delete key/value(accountName/password) pairs from a JSON formatted dictionary(separate .txt file). It's ...
Homer's user avatar
  • 287
12 votes
2 answers
2k views

C# - name separation & last name in upper to Camel

I had an xls file with lots of full names in the following form at work: ...
newbie's user avatar
  • 879
12 votes
1 answer
1k views

Console command tool

I have created a little console tool that simply does commands that you enter. The commands are stored in a txt file. Right now I only got 2 commands: getTime and ...
Sumsar1812's user avatar
11 votes
5 answers
2k views

Counting relevant entries in a large bioinformatics file

I have a working example of a piece of code which opens up a file, gathers information about the contents, and outputs a map which contains the information. The file The file type is an in-house ...
Sam's user avatar
  • 332
11 votes
6 answers
10k views

Parse a simple key=value config file in C

Write a program that should read a file formatted strictly like this below: $ cat sample bingo=2 bingo2=939 bingo3=text The left and right side of ...
Sedmaister's user avatar
11 votes
6 answers
7k views

Standard way of reading file contents to a buffer

I have been trying to write a sample code block to read file contents into a buffer. I am assuming that: Code must be platform independent Should work in all cases(or report proper error) It should ...
Shivendra Mishra's user avatar
11 votes
5 answers
8k views

Most common words in a text file of about 1.1 million words

I'm learning programming with Python. I’ve written the code below for finding the most common words in a text file that has about 1.1 million words. It is working fine, but I believe there is always ...
srikavineehari's user avatar
11 votes
4 answers
541 views

File editing program

I have written a Java class to replace text in file. The file contains database configurations and is as follows: ...
eatSleepCode's user avatar
11 votes
5 answers
10k views

Reading binary file of doubles

I'm trying to read doubles from a relatively small binary file. This currently reads a 100 KB file in about 6 milliseconds in my system. I would like to reduce that if possible. ...
JohnJohn's user avatar
  • 113
11 votes
2 answers
217 views

Ruby format analyser

I have a requirement to validate file names related to architecture after they are uploaded. Once they have been uploaded I must warn the user if the file name is not standards compliant. What's in a ...
Mohamad's user avatar
  • 2,034
11 votes
2 answers
4k views

Reading text from 2 files

I've got 2 simple text files: besede.txt To je vsebina datoteke z besedami. V njej so razlicne besede ki imajo lahko pomen ali pa tudi ne. skrivno.txt 4 3 19 2 3 2 4 3 I wrote a program which ...
user2956514's user avatar
11 votes
3 answers
928 views

Code downloads a text file from a website, saves it to local disk, and then loads it into a list for further processing

My program opens a website and downloads a text file. The text file is a simple file with one word per line. I save the file to local disk and then create a list to hold each line of the text file ...
Duane Whitty's user avatar
11 votes
1 answer
3k views

Simple log rotation script

I created a simple script that implements log rotation. It checks the log file size (say, out.log) if it exceeds 5MB limit. If it does then the script copies it to <...
Dmitry Zinkevich's user avatar
11 votes
1 answer
9k views

File transfer over a stream

I am doing some programming on the side and would just like to know if I'm going in the right direction with my code. ...
archon's user avatar
  • 233
10 votes
8 answers
10k views

Replace strings in a file

I had to create an executable to search and replace strings in a file. This is to be used in my installer for text file manipulation. I have various placeholders in configuration files that I need to ...
msiyer's user avatar
  • 261
10 votes
4 answers
6k views

Comparing two large binary files in C

I'm trying to read two sufficiently large binary files, comparing them and printing the offset at which they differ. I'm using fread to read the binary files and <...
ampat's user avatar
  • 103
10 votes
5 answers
2k views

Basic C copy file implementation

I'm a java programmer by trade and starting to learn C/C++. I'd appreciate any pointers on glaring issues with my code style which is acceptable in java but not in C. I feel like open_files is ...
LiamRyan's user avatar
  • 313
10 votes
5 answers
6k views

Memory-safe file-reading in C

I am trying to write a single function that will read a certain number of bytes from a C file, or the entire file, based on the arguments. I want it to be memory-safe of course, and deal with ...
Tom's user avatar
  • 567
10 votes
3 answers
4k views

Implementation of Linux cp in modern C++

This is my simple implementation of the Unix cp command. It is a C++ program but makes use of some of the lower level C library I/O functions. Any suggestions for ...
halius's user avatar
  • 103
10 votes
4 answers
14k views

Reversing the lines of a file

I am trying to reverse the lines of a file by reading the file through an array. Is there a more efficient and quicker way of achieving this? ...
Mathematica's user avatar
10 votes
2 answers
10k views

Read/write a pipe-delimited file line by line with some simple text manipulation

This code that I wrote is supposed to read/write a pipe-delimited file line by line to a new file with some simple text manipulation. (It also adds two new columns) and publishes a "Status Update" ...
Emily Alden's user avatar
10 votes
2 answers
9k views

Writing a bitmap image from C++

Here's my function that creates a bitmap file from an array of pixels. It can write a bitmap both with transparency and without transparency. Please review my code and give constructive criticism on ...
user170483's user avatar
10 votes
4 answers
306 views

Let's play Find that File

Isn't it annoying when you can't find a file you recently created? Especially when you either have a very disorganized drive or a directory with lots of files. Even if you don't care, isn't it nice ...
TheCoffeeCup's user avatar
  • 9,444
10 votes
3 answers
15k views

Picking random lines out of text files

So I was doing something which creates an airplane with an actual airline code, number, airplane type and so on. The airline code and airplane type are stored in a txt file so I can add more later to ...
marianopicco's user avatar
10 votes
3 answers
36k views

Read hex from file and convert to decimal

I made a small script to read text file that contain hexadecimal and convert to another file in decimal by using command-line as a filename input. ...
Smith Lo's user avatar
  • 125
10 votes
2 answers
28k views

Split large file into smaller files

I recently suggested this method for emulating the Unix utility split in Python. Is there a more elegant way of doing it? Assume that the file chunks are too large to be held in memory. Assume that ...
tommy.carstensen's user avatar
10 votes
2 answers
47k views

User input and reading contents of file

For full disclosure: this is an assignment for my programming class and I just want tips or advice on some of the code. Assignment details just for background information purposes: Write a program ...
jal3524's user avatar
  • 101
10 votes
1 answer
244 views

The answer to life, the universe, and Project Euler

I've never did a real Project Euler in my life, so I figured it was about to do one. And what better Project Euler to start with than Problem 42? Project description from Project Euler: By converting ...
Simon Forsberg's user avatar

1
2 3 4 5
17