Re: Comparing memory with a constant



Ian Collins wrote:
CBFalconer wrote:

.... snip ...

How about the following (using strings for convenience), untested:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#include <strings.h>
void switchonpattern(const char *pattern)
{
static const char *patterns[] = {NULL
,"pattern1"
,"pattern2"
....
,"patternN");

What if a pattern contains a 0 byte?

Note the underlined above. If you want arrays, use arrays and
memcmp. You may then need a length parameter in addition, or a
record with a length field.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

.



Relevant Pages

  • Re: Doubt
    ... int mainis better. ... void change (char *b) ... This is automatically done in the case of arrays, ...
    (comp.lang.c)
  • Re: VLA Question
    ... length arrays): ... void f ... goto again; ... int main(int argc, char * argv) ...
    (comp.lang.c)
  • Re: structure toupperlower?
    ... > I've got char' arrays, nul terminated iterating over the 'isalpha' ... void insert ...
    (comp.lang.c)
  • Re: slurping in binary data
    ... char pattern; ... Look at your previous code for constructing the format string in ... (Or make life easy on yourself and initialize pattern with a ... You certainly can add debugging printf statements at strategic points ...
    (comp.lang.c)
  • Re: WILDCARD: output all a* by searching a text file
    ... where * denotes a string of characters. ... When you want to write a program that search a pattern such as /a./ ... int main{ ... int main(int argc,const char** argv){ ...
    (comp.programming)