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

  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
    596
    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