hwo to define a char array with null value and how to check?

This is a discussion on hwo to define a char array with null value and how to check? within the C++ Programming forums, part of the General Programming Boards category; for exmaple: Code: char buff[6][35]; how to set the whoe array has no value at the beginning and how to ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    hwo to define a char array with null value and how to check?

    for exmaple:

    Code:
    char buff[6][35];
    how to set the whoe array has no value at the beginning and how to if it has and charater inside??
    use the function strcmp()??

    thank you for helping.

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Code:
    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    
    int main()
    {
        int i,j;
        char buff[5][3]={0};  // this initializes the whole thing to 0 (null)
    
        for (i=0;i<5;i++)
            for(j=0;j<2;j++)
                if(buff[i][j])
                    printf("found %c\n", buff[i][j]);
                    else printf("nothing here\n");
    
        strcpy(buff[2],"ab");
    
        for (i=0;i<5;i++)
            for(j=0;j<2;j++)
                if(buff[i][j])
                    printf("found %c\n", buff[i][j]);
                    else printf("nothing here\n");
    
    
        system("PAUSE");
        return 0;
    }

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21