> On 26 May 2007 01:26:13 -0700, J.Broe
@gmail.com wrote:
> >Hi, I've written a some code to assist in my understanding of strings
> >using some of Cs built in character handling functions but I am not
> >sure why I'm getting the following error.
> >I hope someone can explain the errors of my ways.
> It's important to note that C has no string type. The string.h
> functions assume '\0' terminated arrays of char.
> >/* Looking for special chars in testlist */
> >#include <stdio.h>
> >#include <string.h>
> >#include <ctype.h>
> >int main ()
> >{
> > int i;
> > char test2[10] = "ab c1% 4!.";
> too short, your string literal actually is "ab c1% 4!.\0"
> char test2[11] = "ab c1% 4!.";
> better:
> char test2[] = "ab c1% 4!.";
> > for (i=0; i <= 10; i++)
> the test2 index runs from 0 - 10, test2[10] == '\0', therfore
> for (i=0; i < 10; i++)
> prefer sizeof (for arrays) or strlen (for char*) to hardcoded numbers.> {
> > if ((ispunct((int) test2[i])) && (test2[i] != "."))
> // see other postings
> > {
> > printf("i= %d is punct\n",i);
> > }
> > }
> > return 0;
> >}
> --
> Roland Pibinger
> "The best software is simple, elegant, and full of drama" - Grady Booch
Ahhh I see. " " are for strings and ' ' are for chars.