Thread: Scanning a document for tags

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    81

    Scanning a document for tags

    i'm using this code to scan a document for the <script and </script> tags, I'm trying to copy each occurance of javascript from a html file and past is into a seperate edit.
    Code:
              szJava = NULL;
              szBuffer[len] = '\0';
              if(szJava = strstr(szBuffer,"<script"))
              {
                szRemain = strstr(szBuffer,"</script>");
                strcpy(szRemain, szBuffer);
                *szRemain = '\0';
                SetWindowText(hJavaSource,szJava);
              }
              while(szJava != NULL)
              {
                szJava = NULL;
                if(szJava = strstr(szBuffer,"<script"))
                {
                  szBuffer[strlen(szBuffer)] = '\0';
                  szRemain = strstr(szBuffer,"</script>");
                  strcpy(szRemain, szBuffer);
                  *szRemain = '\0';
                  AddWindowText(hJavaSource,szJava);
                }
              }
    if i only use the first part of this, the section not in the while loop it works fine but only finds the first occurance of the script tag. but once i added the while loop in it, it crashes with an Access violation message. is there anything wrong with the code or a better way to do this?

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>strcpy(szRemain, szBuffer);
    Should be szBuffer = szRemain;
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    it still crashes, any other ideas?

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You replaced both instances of it? Another thing that might crash it is if they have <script> and </Script>.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Document Class and Dialog Windows :: MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 12-01-2002, 12:27 AM
  2. stopping some scanning
    By aoe in forum C Programming
    Replies: 4
    Last Post: 06-09-2002, 01:50 PM
  3. MultiDocument And MultView (and per document) :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 04-09-2002, 09:00 AM
  4. Scanning a line in a document
    By bc120 in forum C Programming
    Replies: 5
    Last Post: 01-02-2002, 02:06 PM
  5. Getting document point co-ordinates
    By swordfish in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2001, 12:37 PM