I'm trying to read only the strings from an image file. I was able to successfully read all the strings in the image file using java. I wrapped the inputstream into a filereaderstream which is again wrapped inside of a bufferereader. so now i can extract all the strings from the image file (like xmp tags and exif, tiff tags etc) ..
how do i accomplish the same thing using c.
Thanks
If you are using unix based OS, you can use the (unix, not C) command strings.
Related
I have an array of English words that is about 275,000 elements long that I need to use for my iOS app written in Swift. However, Xcode doesn't seem to be able to handle such a large (3+ MB) file. The file will not open in Xcode, and when I attempt to compile the app, it seems to compile indefinitely and never build.
How should I handle this large amount of data?
Don't put a huge literal array in your swift source code.
Instead, create a text file, drag that into your project as a resource, then open that and convert it into an array at runtime using components(separatedBy:).
For speed and storage efficiency you could instead write a conversion utility that reads your text file and uses components(separatedBy:) to convert it to an Array of Strings. Then you could write the array of Strings to a binary plist.
You could then drag the plist file into your project as a resource, and write code that reads the plist file into an Array at launch.
How about put it in a file and read it at runtime? For example, put the elements in the a JSON array and store the array in a text file. Drag the file into your Xcode project, then it will be copied into the app bundle during compilation. Read the JSON array from the file and parse it at runtime.
There are many Tutorial on the internet about reading files in bundle and parse JSON data.
I need some help.
I'm writing a program that opens 2 source files in UTF-8 encoding without BOM. The first contains English text and some other information, including ID. The second contains only string ID and translation. The program changes every string from the first file by replacing English chars to Russian translation from the second one and writes these strings to output file. Everything seems to be ok, but there is BOM appears in destination file. And i want to create file without BOM, like source.
I open files with fopen function in text mode with ccs=UTF-8
read string with fgetws function to wchar_t buffer
and write with fputws function to output file
Don't use text mode, don't use the MS ccs= extension to fopen, and don't use fputws. Instead use fopen in binary mode and write the correct UTF-8 yourself.
I have the following config file:
[GENERAL_CONFIG]
filter_subnetworks = 192.168.105.0/24 1.1.0.0/16 192.168.105.0/24
192.168.105.0/24 1.1.0.0/16 192.168.105.0/24
192.168.105.0/24 1.1.0.0/16 192.168.105.0/24
and i want to read all subnetworks with g_key_file_get_string_list (gkf, "GENERAL_CONFIG", "filter_subnetworks", &s_len, &error) but this function read one single line.
It looks like your input file doesn't comply with the formatting required by the glib Key-value file parser functions.
All key values should be on a single line, and you should have an explicit list separator character (not just space) such as ; or ,, see the g_key_file_set_list_separator() function.
Convert the file to comply with the required glib format if you're going to use their API. Note that as soon as you save your file back out, it will use the glib API, so there's little point in "tricking" it to load something else.
I have a binary file (.bin) and a (.txt) file.
Using Python3, is there any way to combine these two files into one file (WITHOUT using any compressor tool if possible)?
And if I have to use a compressor, I want to do this with python.
As an example, I have 'file.txt' and 'file.bin', I want a library that gets these two and gives me one file, and also be able to un-merge the file.
Thank you
Just create a tar archive, a module that let's you accomplish this task is already bundled with Cpython, and it's called tarfile.
more examples here.
there are a lot of solutions for compressing!
gzip or zlib would allows compression and decompression and could be a solution for your problem.
Example of how to GZIP compress an existing file from [http://docs.python.org]:
import gzip
f_in = open('file.txt', 'rb')
f_out = gzip.open('file.txt.gz', 'wb')
f_out.writelines(f_in)
f_out.close()
f_in.close()
but also tarfile is a good solution!
Tar's the best solution to get binary file.
If you want the output to be a text, you can use base64 to transform binary file into a text data, then concatenate them into one file (using some unique string (or other technique) to mark the point they were merged).
I am currently taking a curse in C programming, and for our final project we need to read some text from a pdf into a string, so we can manipulate the string.
In essence what i am looking for is something similar to this, only with a .pdf instead of a .txt file.
char *line;
fscanf(myfile.txt," %[^\n]", line);
I have no experience with ghostscript, so I have no idea if this is even possible, although we where told that we should use ghostscript.
The current version of Ghostscript includes the 'txtwrite' device, which will extract text from any supported input (PostScript, PDF, XPS, PCL) and will emit it in a variety of forms.
The UTF-8 output would probably be most useful to you.
Caveat! Many things which appear to be text in PDF files are not text, and no attempt is made to deal with these.
ps2ascii is deprecated with the release of the txtwrite device, but in any case its perfectly capable (despite the name) of dealing with PDF as an input.
I can't think why anyone assigned you this project, PDF files are not text files, and cannot be treated as such. In addition to the fact that PDF files are generally compressed, identifying the contents stream and all the other streams it relies on (which may themselves include text) is non-trivial. Plus, the text is often encoded in a way which can be difficult to understand (this is particularly true of CIDFonts and TrueType fonts).
Perhaps your tutor expected you to first become expert in the PDF format, but that seems excessive for a C course.
You can convert your PDF to Postscript using pdf2ps, and then to ASCII using ps2ascii. You already know how to read ASCII.
Both utilities mentioned are in the ghostscript package.