< and > as characters in C?
#1
I was trying to write a filter to locate some things in HTML and I was quite surprised by this.  If I do strstr() to search for <label> it's not found, but grep or search in the mc file viewer can find it.
I even tried putting them in as ASCII codes: snprintf(lbl,20,"%clabel%c",0x3c,0x3e); and it doesn't find them in the HTML.  If I look at the HTML in hex mode of mc's file viewer they seem to be normal ASCII, not unicode.

This is nothing specific to a PBP except that I'm using gcc under Daniel Thompson's Bullseye on one.  I tried escaping them by putting a \ in front of each one, that doesn't work.  I'm pretty sure I've searched for HTML tags in C years ago, I don't remember this strangeness.
  Reply
#2
Well, even clang works the same way. Or doesn't work.
  Reply
#3
@ab1jx This is a coding problem, not a Pinebook Pro problem.

In the case you want help, you should post a small snippet of your code that demonstrates the problem. I highly doubt both gcc and clang have some problem, especially given all the programs running on your machine were compiled with one of those and all seem to work.

Regarding the search function strstr() [1]:

1. Sanity check that the example given in tutorialspoint works [1] - if it doesn't, you really have massive problems.

2. Does the haystack contain the full string? Try printing it... Perhaps you are not getting the result you think you are from the GET request.

3. Is there a NULL character `\0` early on in the string?

4. Remember that strstr() is going to return a pointer to the offset where the string was found - not the offset in the string, so you need to check it against NULL. If you try to do something like `haystack[strstr(haystack, needle)]` you will almost certainly segmentation fault.

[1] https://www.tutorialspoint.com/c_standar...strstr.htm
  Reply
#4
Yeah, I just wrote this little test and it works OK.
Code:
/*
  Show the bug
*/

#include <string.h>
#include <stdio.h>

char testdata[] = "foo xyzzy <tag> nonsense <label> junk more junk";

int main(void) {
  if (strstr(testdata,"<tag>") == NULL)
    printf("tag not found\n");
  else
    printf("tag found\n");
  if (strstr(testdata,"<label>") == NULL)
    printf("label not found\n");
  else
    printf("label found\n");
  return 0;
}
The real thing has 5 MB of data, too much to post.
  Reply
#5
@ab1jx If the small example works, then the problem is something in your code most likely.
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Keyboard types random characters erock22 10 10,946 10-30-2020, 08:53 PM
Last Post: erock22
  Darktable - characters are square PaulQ 7 10,019 09-13-2020, 10:38 PM
Last Post: kenigan

Forum Jump:


Users browsing this thread: 1 Guest(s)