Null terminated strings HELP !

  • 18 years ago

    I have a pointer to a string, the ponter is called pchar.


    i loop through the string like so...


    int N = 0
    while ( *(pchar+N) != '\0' )
    {
    N++
    }


    //N now holds the length of the string...


    The problem is, the loop goes forever,, and i KNOW the string is null terminated,,, am i just being dumb ?? HELP !!

  • 18 years ago

    Hi,


    I tried it and it did work fine? He is the test:
    [ccode]

    include <stdio.h>



    int main()
    {
    int N = 0 ;
    char *pchar = "livro";
    while ( *(pchar+N) != '\0' )
    {
    N++ ;
    }
    printf("Length = %d\n", N);
    //N now holds the length of the string...
    return 0;
    }
    [/ccode]


    Can u give me a bigger peace of ur code?

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”