Thread: Finding string after another string at an unknown location in a file

  1. #1
    Registered User
    Join Date
    Sep 2017
    Posts
    1

    Finding string after another string at an unknown location in a file

    I am relatively new to C programming and much that i once know I've forgotten so maybe i just need a little nudge in the right direction.

    I have a long body of text and I'm attempting to look through it until i find a specific sequence of characters.

    Once i get to that point i want to save the next certain amount of characters as a different string.

    My thought was to use fprintf command but then id fave to get to that point first.

    Is there an easier way to do this?

    Here is a sample of my text file

    <Folder id="layer 0">
    <name>pls_10_rev_nad83</name>
    <Placemark>
    <styleUrl>#falseColor0</styleUrl>
    <ExtendedData>
    <SchemaData schemaUrl="#S_pls_10_rev_nad83_DDDDSSSSIDDSSSSSS">
    <SimpleData name="AREA">497297</SimpleData>
    <SimpleData name="PERIMETER">3474.15</SimpleData>

    I would want it to output:
    497297, 3474.15

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    And if your XML happens to be formatted as
    Code:
    <SimpleData name="AREA">
        497297
    </SimpleData>
    <SimpleData name="PERIMETER">
        3474.15
    </SimpleData>
    then what?

    Sure, you can bumble through with fgets() and strstr(), and build some ad-hoc one-off program that needs to be rewritten every time you need to do something slightly different.

    Or, GitHub - libexpat/libexpat: Expat library: Fast XML parser in C; in the process of migrating from SourceForge to GitHub
    Yes it's a lot more work up front, but at the end you'll have something of a useful skill.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 20
    Last Post: 03-08-2011, 05:16 PM
  2. find a string based on the location of another string
    By rlilley in forum C Programming
    Replies: 3
    Last Post: 02-19-2009, 12:29 PM
  3. question about using a string as a file location
    By johnnyg in forum C++ Programming
    Replies: 3
    Last Post: 02-14-2006, 05:45 PM
  4. Finding a String in a file
    By Silverdream in forum C Programming
    Replies: 5
    Last Post: 03-23-2002, 12:16 PM

Tags for this Thread