file-io

search in a file for a specific line c code

我们两清 提交于 2020-01-16 09:10:12
问题 I am working on C. I would like to ask what s the best way to search in a file for a specific line (or multiple lines)? Can someone please give me an example. I have 2 files and I would like to see if this two files are 80% identical. I thought about searching in one of the file some specific lines from the other file. Thx I need some example in C code. here is a small example int compareFile(FILE* file_compared, FILE* file_checked) { bool diff = 0; int N = 65536; char* b1 = (char*) calloc (1

Copy to output directory issue with .inf file

若如初见. 提交于 2020-01-16 08:40:12
问题 Apologies if dup, I did try searching several times and found nothing like it... I have a number of 'config' files that my application edits. Really it is just a gui for editing these files as they have a special format. Anyway, everytime I put a new group of files in visual studio, and select "Copy to Output directory" to "Copy always", this works fine. Except all other files will have "Build Action" set to "None" except the .inf file which will always have "Build Action" set to "Resource"..

How to read stdout from a FILE* created with libexpect in C++ on linux?

不问归期 提交于 2020-01-16 08:23:09
问题 Using C++ I created a FILE* using libexpect: FILE* fd = exp_popen("ssh root@sunblaze"); I got to the command line using: exp_fexpectl(fp , exp_exact , "password: " , 1 , exp_end); Now the other posses in bash shell and I want to get the contents of a file there, so I have to run the command cat /port1/port and get all it prints in a char buffer. How do I do that? fgets doesn't seem to work... Thanks in advance 回答1: Assuming that your machine and "sunblaze" are within a firewalled off,

Does the address of a function change per runtime [duplicate]

北城以北 提交于 2020-01-16 01:01:15
问题 This question already has answers here : Why does the address of a function change with every run? (4 answers) Closed 4 days ago . I'm writing something in c++ where I want to read text from a file that indicates correlations between Strings and Functions I have declared in my program. For example the file could read: sin:sin PI:getPi +:add I wanted the code to take this and create a hash table or vector of String and Function Pointer data structures. Unfortunately, I realize that code would

Pattern matching in Thousands of files

有些话、适合烂在心里 提交于 2020-01-16 00:49:11
问题 I've a regex pattern of words like welcome1|welcome2|changeme ... which I need to search for in thousands of files (varies between 100 to 8000) ranging from 1KB to 24 MB each, in size. I would like to know if there's a faster way of pattern matching than doing what I have been trying. Environment: jdk 1.8 Windows 10 Unix4j Library Here's what I tried till now try (Stream<Path> stream = Files.walk(Paths.get(FILES_DIRECTORY)) .filter(FilePredicates.isFileAndNotDirectory())) { List<String>

grep: search once for different pattern and output to several files

浪尽此生 提交于 2020-01-15 20:33:24
问题 Is it possible to tell grep to use different output files for every type of matching search string? I need to search all *.log recursively to find all "[ERROR]", "[WARN]" and "[ASSERT]". But I would like to have it separated in different output files. One output file for each search string. (without calling grep several times!) searching already works: (called from gmake) grep -nHr --include=*.log -e '\[ERROR\]' -e '\[WARN\]' -e '\[ASSERT\]' $(root_path) > $(root_path)/result.txt But due to

grep: search once for different pattern and output to several files

ぐ巨炮叔叔 提交于 2020-01-15 20:28:09
问题 Is it possible to tell grep to use different output files for every type of matching search string? I need to search all *.log recursively to find all "[ERROR]", "[WARN]" and "[ASSERT]". But I would like to have it separated in different output files. One output file for each search string. (without calling grep several times!) searching already works: (called from gmake) grep -nHr --include=*.log -e '\[ERROR\]' -e '\[WARN\]' -e '\[ASSERT\]' $(root_path) > $(root_path)/result.txt But due to

What is the difference between FileSink, StringSink, Filesource, StringSource Crypto++

北战南征 提交于 2020-01-15 20:15:06
问题 I am reading in an image, encrypting it, then decrypting it. The goal is to be looping this eventually and recording the time it takes for the process to complete. Currently what I have it reads the file in, then it encrypts it, encrypts it, the creates another file based on the recovered data. I don't need to make another file with the decrypted picture. Previously I had been using StringSource and StringSink , but that only worked for text files. I received some help at How to read an image

FileWriter() will only append, not overwrite

僤鯓⒐⒋嵵緔 提交于 2020-01-15 12:24:28
问题 I have a method that is supposed to overwrite the current file with new content, however the FileWriter() is only appending the new content, not overwriting the old content. This is how my FileWriter is set up File file = new File(test.txt); BufferedWriter out; out = new BufferedWriter(new FileWriter(file, false)); Here is the save method //stuff is defined earlier and filled with the new content for the file ArrayList<String> stuff = new ArrayList<>(); //The actual save() method Object[]

Opening, Editing and Saving text in JTextArea to .txt file

感情迁移 提交于 2020-01-15 12:15:27
问题 I am messing around with java swing and am trying to open a text file containing existing data with a JTextArea. It doesn't seem to be saving any changes regardless of the different things I have tried. Below is code that reads the text file fine, but doesn't write it (obviously). If someone could please advise me as to how I could successfully save changes to the JTextArea I would be greatful. package funwithswing; import java.awt.*; import javax.swing.*; import java.io.*; import java.util