try this one...just look at it carefully and i believe u will identify the mistake u were making...

Code:
void main() {
    int i,j;
    char d;
    char a[4][4] = {0};
    ifstream myfile1 ("p.txt");
    ofstream myfile3 ("c.txt");
    if (myfile1.is_open()) {
        while(!myfile1.eof()) { 
            for (j = 0; j < 4; j++)
                for (i = 0; i < 4; i++) {   
                    myfile1.get(d);
                    a[i][j] = d; // plaintext               
                    d = 0;
                    cout<<a[i][j];
                }   
            if (myfile3.is_open()) {
                for(j = 0; j < 4; j ++)
                    for ( i = 0; i < 4; i++) {
                        if (a[i][j])
                        myfile3<<a[i][j];   
                    }
            } else 
                cout << "Unable to open file";  
        }
        myfile3.close();
    } else 
        cout << "Unable to open file";
    myfile1.close();
}