Reading an integer size element from file

Hello, I need some help for reading an integer size element from a file. In C++ there is the function fread with the following signature size_t fread(void ptr, size_t size, size_t nitems, FILE stream); where size is the size of one of the elements. Using this function in c++, you can read an integer by setting size = sizeof(int). I need this function because I am writing in a file a lot of integers and characters without any separator and I need to take the first element which is always an integer. Here is an example:
I have: int x = 234; String y = "12ABC". I write those two elements in an output file. Now, when reading from that file the content of the file is: 23412ABC and I need to take the two elements x and y.
Can anyone help ?

I see what you mean but the problem is a bit more complicated, maybe I did not explain well. I need to copy data in a text file and retrieve them. Most data that will be written in the file are stored in an char array. those data may contain digits, letters, special characters... depending on their ASCII code. But before writting that char array, I need to write an integer corresponding to a specific index and I have no way of predicting the number of digits of that integer. So for example, my char array contains the following data: {'1','2','3','a','b','c'} and my int equals 10000. Using FileWriter I write the int and then the char array using the method myfile.write with its arguments. Next step, I want now to read from myfile.txt the data that I wrote in the first step. I start reading the int then using myfile.read(mychararray, 0, 6) /*6 being the size of the bloc to be read*/ I read the remaining characters and store each char in a cell of mychararray. The problem with this, is that using the method .read I can not read the first integer since I don't know its size: it may contain 1, 2 or even more digits.
I know that storing everything in bytes would make my task easier, but I necessarily need to store an array of characters and then use .read method to store the content of the file (after having read the int of course) in a char array. Last clarification, the step of writing int then char array is reproduced n times before calling myfile.close();
I hope it is clearer than before. Any suggestion for this problem would be welcome.

Similar Messages

  • How to read data in binary form from file?

    Hi,
    i try to write an implementation of LZW. I need to read data in binary form from a file. How can i do that? I cannot find something like "binary input stream" ...
    Thanks

    Hi,
    i try to write an implementation of LZW. I need to
    read data in binary form from a file. How can i do
    that? I cannot find something like "binary input
    stream" ...
    ThanksInputStream reads bytes. I don't understand your question.

  • Reading non-standard variable types from file

    Hi,
    I'm currently on a programming course, and I need some help with an excercise.
    The excercise is about adding save, load and undo features to an Infocom style text adventure. The save file must contain three variables: The location of the player (Area), the items the player had (ArrayList<Item>) and the number of passed turns (int.)
    Is it possible to write to & read from file with these type of variables? Or do I have to convert them to Area to String (saving) and from String to Area (loading)?
    Thanks for the help in advance.

    You should probably take a look at Java Serialization (google on that)
    Kaj

  • Read settings/c​onfigurati​ons from file

    Hi,
    I am developing a program that reads from several thermocouples. The reading can then changed by an offset and gain factor.  What I want to achieve is once the user has calibrated the sensors he can click on a save button to save those offset and gain values to a file. The next time the program is launched it reads the file for the calibration values (so the user does not have to calibrate them all the time). 
    How is the best way of doing this in LabView
    regards
    Harshil.

    I also enjoy using the OpenG Variant Configuration File VIs Read and Write Ini File VIs.  The Write/Read Panel to/from INI VIs look interesting, too, but I've never used them.  I use the others all the time.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • Anyone have example to read and write XML to/from file

    I am writing a swing utility and need to save and read data in XML. I have looked around google, but the examples are just confusing me.
    Jonathan

    Do these xml docs have dtd's? And specific DOM implementation needs or just a custom xml?
    I have some examples in http://cvs.sourceforge.net/viewcvs.py/mathml-x/mathml-x/src/com/neuralworks/physics/Academy.java?view=markup
    follow openMenuItemActionPerformed and openFEMMLDocument(String filePath). Look for DocumentBuilder
                DocumentBuilderFactory factory =
                DocumentBuilderFactory.newInstance();
    /*            factory.setAttribute("element.factory",
                                     ELEMENT_FACTORY);
                factory.setAttribute("attribute.factory",
                                     ATTR_FACTORY);
                DocumentBuilder builder = factory.newDocumentBuilder();
                //builder.setEntityResolver(new X3DEntityResolver());
                //builder.setErrorHandler(new X3DErrorHandler());
                femDoc = findXMLFile(builder, filePath);
                org.w3c.dom.Element docElement=femDoc.getDocumentElement();
                javax.swing.tree.DefaultMutableTreeNode dmtn=new javax.swing.tree.DefaultMutableTreeNode("FEMML");
                javax.swing.tree.DefaultMutableTreeNode svgChild=new javax.swing.tree.DefaultMutableTreeNode(docElement.getNodeName());
                //System.out.println(svgDocument.getTitle()+" nv "+svgSVGElement.getNodeValue());
                //recurseDOM2TreeNodes(svgChild, docElement.getChildNodes());
                dmtn.add(svgChild);
                JTree tree=new JTree(new javax.swing.tree.DefaultTreeModel(dmtn));
                tree.setRootVisible(true);
                tree.setShowsRootHandles(true);
                tree.setEditable(true);
                //try
                    //X3DTreeAdapter x3dTreeAdapter=new X3DTreeAdapter(x3dDTDParser.parse());
                    //org.web3d.x3d.dom.swing.DOMTreeCellEditor domTreeCellEditor=new org.web3d.x3d.dom.swing.DOMTreeCellEditor();
                    //tree.setCellEditor(domTreeCellEditor);
                    //org.web3d.x3d.dom.swing.DOMTreeCellRenderer domTreeCellRenderer=new org.web3d.x3d.dom.swing.DOMTreeCellRenderer();
                    //domTreeCellRenderer.addMouseListener(x3dTreeAdapter);
                    //domTreeCellRenderer.addMouseMotionListener(x3dTreeAdapter);
                    //tree.setCellRenderer(domTreeCellRenderer);
                    //tree.addMouseListener(x3dTreeAdapter);
                    //tree.addMouseMotionListener(x3dTreeAdapter);
                    academicSplitPane.setLeftComponent(new JScrollPane(tree));Lot of commented out stuff I need to clean up. There are other examples of opening specific xml docs that have special DOM implementations; svg and mathml for example.
    For saving I use xslt with an identity transform to go from an in memory DOM source to an xml document on disk.
    Follow the saveAs(String filePath) method and the identity.xsl is http://cvs.sourceforge.net/viewcvs.py/mathml-x/mathml-x/stylesheets/identity.xsl?rev=1.2&view=markup

  • How to Read specific data from file and do a calculation and display on the output

    FYI: Below is the function use for the writing:
    -OpenFile(use ASCII)
    -sprintf
    -WriteFile
    Example: Output from the doc file
    …EndTime: 09:34:48 program time: 0.567663 sec
    …EndTime: 09:36:48 program time: 0.666666 sec
    My objective is to read data 0.666666 (FYI: is last sentence of the file) to do some calculation. How can we read specific data(specific location) from file..
    Any advice or help?
    What is the function needed?

    I would consider counting line feeds and checking for end-of file to isolate the last line, which then can be read using fscanf...
    Have a look at getc...
    character = fgetc ( stream );
    if ( character == '\n' ) // new line
    if ( character == EOF ) // end-of-file

  • If I'm copying text and/or vector elements from Indesign to Photoshop how come their pixel sizes change even though I opened the same sized document and my indesign file is a web file?

    If I'm copying text and/or vector elements from Indesign to Photoshop how come their pixel sizes change even though I opened the same sized document and my indesign file is a web file?

    >my indesign file is a web file
    Pardon?
    Or do you mean that, when you created a new document, you choose Web as intent maybe?

  • Is there a way to select a certain box of elements from a csv file and read that into LabVIEW?

    Hello all, I was wondering if there was a way to select only a certain "box" of elements from a .csv file in LabVIEW? I have LabVIEW 2011 and my main goal is to take two arrays and graph them against each other. I can import the .csv file just fine and separate each row and each column to be its own, but say I have an 8X8 but want to graph the middle 4X5 or something like that. Is there any way to extract an array without starting at the beginning and without ending at the end? Thank you in advance.
    Solved!
    Go to Solution.

    Hi Szklanam,
    as a CSV file is just a TXT file with a different suffix you can read a certain number of lines of that file. So you can limit the number of rows in your resultung array. To limit the number of columns you still have to use ArraySubset, so maybe it's a lot easier to read the full CSV file and pick the interesting spots with ArraySubset...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How to re-read metadata from file in Photoshop Elements 11 Organizer?

    I am currently testing Lightroom 4 and Photoshop Elements 11 as a replacement for my old softwarestack due to a new DSLR.
    In Lightroom I can read and write metadata directly from/to file. In Photoshop Elements Organizer I have found an option to write tags to files, but none to re-read the metadata after the files has been imported to the catalog.
    I would like to use Lightroom as primary organizer for import/tagging/basic corrections. But Lightroom does not have some nifty things like face/person recognition and SmartTags, so I need the Photoshop Elements Organizer to do that. The target workflow would be:
    DSLR -> Import to -> Lightroom -> tagging -> basic corrections -> write tags to file in Lightroom -> import to PSE organizer -> person recognition -> smart tags -> image edits -> write tags to files in PSE organizer ==> tags can now be re-read in Lightroom, so I get the PSE organizer changes to Lightroom.
    And that is the problem: If changes were made after this workflow in Lightroom, PSE Organizer does not know that until I can re-read the metadata from the files. If I press "write tags to file" in PSE organizer all newer Lightroom tags will be overwritten with the old tags from PSE organizer.
    Does anyone knows a solution for this problem? Or should I file a feature request for both programs?

      You can now do a lot more in the metadata panel in PSE 11. If you select a thumbnail in Organizer and click the three small dots it will bring up a dialog for the metadata fields. To add information to many photos all at once, select all the thumbnails, click the information tab and then click the button marked Add IPTC information. You can then choose to append new information to all of the selected items or to overwrite.
    See image below

  • Read flash movie size from file

    hi,
    does anybody know how i can read the display size of a flash movie (i can access the movie thru an input stream)? i know flash doesn't have a fixed size but i'm pretty sure it should have something like a default size though.
    thakns for help,
    marco

    You could parse the HTML the flash file is shown in and get it's size.
    But I looked through a Flash 4 file I have, and I don't find the size that I know I designed it to be written anywhere in it. It was a quick run-through of the file, though, so I could be wrong. But it would make sense since it's essentially vector graphics, so size isn't important.

  • How to retrieve elements from 3 different xml file in one url

    Hi all,
    Could anyone please let me how can we retrieve elements from 3 different xml file in one url?
    i just can only do it with one file only, any help would very appreciate.
    Thank in advance
    Jim

    Hi Philip
    Thanks for replying me.
    I tried on that way, In my mdx query i am using one slice attribute (i.e [Customer].[Gender].allmembers) in rows so getting error "The  Hierarchy already appears in Axis1".
    SELECT
    {[Measures].[Internet Sales Amount] } ON 0,
    NON EMPTY
    {[Customer].[Gender].allmembers } ON 1 -- Used
    FROM
    [Adventure Works]
    WHERE
    [Customer].[Gender].&[M]
    ,[Product].[Size Range].[(All)]
    ,[Customer].[Country].[All Customers]
    [Customer].[Gender].[All Customers]
    ,[Product].[Size Range].&[XL]
    ,[Customer].[Country].[All Customers]
    [Customer].[Gender].[All Customers]
    ,[Product].[Size Range].[(All)]
    ,[Customer].[Country].&[Australia]
    Can you provide alternate ways to get resolved.
    Thanks in advance

  • File won't open to edit in Elements from LR2

    When choose to open LR photo in external editor Elements 6.0, Elements opens, but the photo (jpg or cr) doesn't open. What to do?
    File opens ok to edit in CS4.
    Can open in Elements on Laptop 1, running Vista. Not working on Laptop 2 running XP.Elements opens files ok on it's own, but not from LR.
    Camera Raw plug in on Elements 6..0 is 4.2, ADM is 3.10.12.
    Have optimized catalog.
    Any ideas will be greatly appreciated.
    Dee

    I've continued to work on the puzzle without success. Have uninstalled & reinstalled PSE6. Have cleared preferences. Have defragged. Have run repair in add/remove programs. Have downloaded trial version PSE7. Same result with PSE7. Program opens, file doesn't. I tried booting in safe mode & PSE6 wouldn't open at all with LR open.
    I'll play around with startup items in msconfig next, but basically not expecting to use PSE as an editor on this computer.
    Again, I get no error messages, the program opens from LR, but the file doesn't.
    Thanks for input.

  • Premiere Elements 11 file sizes

    Premiere Elements 11 file sizes?
    I recorded small 170MB and larger 570MB videos with audio using HyperCam 3.
    Both load and play back in Windows Media Player (ver 12.0.7601.18150) without a problem.
    I can load and play back the small files in Premiere Elements 11 without a problem.
    But, when I load the larger file into Premiere Elements 11, only the sound track loads and plays.
    No video track and the preview screen is a solid black box on my monitor.
    Is there a file size restriction in using Premiere Elements 11?

    Martyson 2010
    By the time I downloaded and looked at your sample video, I see that you and nealeh have worked out a workaround, that is, converting your Microsoft Video 1 (CRAM).avi (1920 x 1080 @ 10 frames per second) to H.264.mp4 (1920 x 1080 @ 30 frames per second.
    I was able to convert your sample video into H.264.mp4 (1920 x 1080 @ 30 frames per second using the free HandBrake program). All 11 minutes 52 seconds of the H.264.mp4 imported into Premiere Elements 11 without issue.
    In the case of these converters, we are dealing with changes in at least video compression, file extension, and frame rate.
    However
    The tests brought up some interesting questions
    1. When I ran your file through the gspot utility, the video codec was shown as Microsoft Video 1 (CRAM), but it listed Codec NOT installed.
    2. In spite of the Codec NOT installed, I was able to play back your video in Windows Media Player and VLC Player.
    3. Your Microsoft Video 1 (CRAM).avi imported with the complete duration of the file, but only audio, no video.
    Further
    4. When I ran my own Premiere Elements 11 created Microsoft Video 1 (CRAM).avi (30 frames per second, 11 min duration) through gspot, the video codec was shown as Microsoft Video 1 (CRAM), but it listed Codec NOT installed - same as yours.
    5. Yet, my file imported into Premiere Elements 11 completely (video and audio).
    6. I need to run a Microsoft Video 1 (CRAM).avi 10 frames per second, 11 min duration) to see if I get the same results as in 5.
    When you record your video, do you have the option of changing the frame rate from 10 to 30 frames per second?
    So, some of the questions that the remain for me
    a. Why is my Premiere Elements 11 created Microsoft Video 1 (CRAM) appearing to be different from the Microsoft Video 1 (CRAM) that you use in your file?
    b. Why is gspot telling me that the Microsoft Video 1 (CRAM) codec is not installed when I can use it in Premiere Elements 11 for the import and export of my own file?
    ATR

  • I have Adobe Photoshop Elements 10. However it converts all my pdf files to Photoshop Elements 10 so I can not email them because no one can read them they are not pdf files anymore. What do I do?

    I have Adobe Photoshop Elements 10. However it converts all my pdf files to Photoshop Elements 10 so I can not email them because no one can read them they are not pdf files anymore. What do I do?

    Nothing has been converted. You first need to convince yourself of this.
    Start Adobe Reader (or Adobe Acrobat, if you have it). Use Open from the File menu. Pick one of your PDF files. Does it open OK? If not, what happens?
    Ok, these emails. What exactly happens when trying to open them?

  • Delete elements from XML file using DOM and java

    Hi
    I want now is to remove element from my XML file
    for example
    i have following xml
    <?xml version="1.0" encoding="UTF-8"?>
    <printing>
    <firstLineTexts>
              <firstLineText />
              <firstLineText>|line11</firstLineText>
              <firstLineText>|line12</firstLineText>
    </firstLineTexts>
    </printing>how do i remove all elements fireLineText
    my final output should be
    <?xml version="1.0" encoding="UTF-8"?>
    <printing>
    <firstLineTexts>
    </firstLineTexts>
    </printing>How do i do it using DOM,
    I can create instance of DOM and write it using TransformerFactory
    Ashish

    Hi
    I am trying the following code,
    but it is not working
                    NodeList nScene = doc.getElementsByTagName("firstLineTexts");
              NodeList nScene1 = nScene.item(0).getChildNodes();
              for (int i = 0; i < nScene1.getLength(); i++)
                   Node n = nScene1.item(i);
                        nScene.item(0).removeChild(n);
              }

Maybe you are looking for

  • Not able toView Data in Answers

    Hi, I created small Repository sai.rpd but when i logon to the answers i am un able to see the data. i am getting the below error Odbc driver returned an error (SQLExecDirectW). Error Details Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P State: HY000. Code

  • LOCKS checking user locked and SQL that he is executing

    Hello all, I have this script that inserts into a table the user causing the lock and the users waiting for the lock to be released. What I would like to add into this the script is the SQL string that the user causing the lock and the users waiting

  • Default settings for gr based ir check box for asset PO

    dear experts,               in vendor master record in purchasing data tab i have checked gr based iv check box, and hence whenever i am creating a Po with X vendor for material system is automatically  checking the check box in po for gr based iv bu

  • Adding header info from JPD Proxy client

    We have created a JPD RMI Proxy. The JPD has a JMS execution path and an http execution path. We set the headers by actually creating the http message themselves. We can use the generated proxy jar and call it from a client. It does work. The problem

  • G5 1.8GHz stalls at blue screen

    Hi all, hope you can help. I recently bought a G5 1.8GHz June 2004 model as parts not working on ebay, so as someone new to Mac I need a little more direction than reading forums. Hardware - I reseated RAM, 2x256MB in the recommended position; new Ha