Searching string for characters



Hi, I've been experimenting some more with strings, I've written some
code where I want to test to see if a certain character char_a is in
the testlist string. Simple enough.
The problem is when testlist contains characters other than letters
and numbers such as comma, full stop and double quotes.

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

int main ()
{
char *testlist = "This is a test,."";
char char_a = 'a';

if (strchr(testlist,char_a) != NULL)
printf("Found in testlist \n");
else
printf("Not found in testlist \n");

return 0;
}

Upon compiling with gcc -Wall -Werror -W -O, I get
searchstring.c: In function `main':
searchstring.c:6: error: missing terminating " character
searchstring.c:7: error: parse error before "char"
searchstring.c:9: error: `char_a' undeclared (first use in this
function)
searchstring.c:9: error: (Each undeclared identifier is reported only
once
searchstring.c:9: error: for each function it appears in.)

The comma, full stop are no problems but it's the extra " that's
causing the issue.
The reason that I have a double quote in my testlist is that I want to
call another function if it's found.
Is it possible to get the extra double quote in my testlist or have I
gone about this the wrong way ?
Thank you for any advice.

Pat

.



Relevant Pages

  • Re: Any iMac rumors?
    ... replaced with a comma. ... The character in question is a right single quote on Windows. ...
    (comp.sys.mac.system)
  • Re: How to change ALL comma in a CEdit into double byte comma?
    ... Then modify the strings to contain the characters you need before adding ... If you need to turn one character into two you could ... the user press the comma key or there is old data which has comma and needs ...
    (microsoft.public.vc.mfc)
  • Re: Unicode Support
    ... > Not knowing much about UTF-8 (my Unicode knowledge extends as far as ... > literal strings of this form as long as the character code for quote ... > can never appear in a MBCS (multibyte character sequence). ... then XP Notepad directly understands UNICODE and you can ...
    (alt.lang.asm)
  • Re: Need help on string manipulation
    ... better to convert strings to UCS-32 before manipulation? ... Characters represented by wchar_t must use one wchar_t per character, ... which may use a multibyte encoding. ... use some newer Unicode characters, if this is a problem for you, then ...
    (comp.lang.c)
  • Re: Regex question
    ... First, if you're using character sets, there's no need to use a or in there. ... This will capture all directories until it can no longer find a trailing slash. ... It will capture any chracter that isn't a singel or double quote. ... The last would even be optional as it's already caught by the filename expression. ...
    (microsoft.public.dotnet.languages.csharp)