Reading atomic coordinates from a PDB file in C
0
1
Entering edit mode
7.2 years ago
souparnoa91 ▴ 20
#include<stdio.h>
#include<string.h>

int main()
{
    FILE *pdb;
    pdb=fopen("5an3.pdb", "r");
    if(feof(pdb))
    {
        fprintf(stderr,"File reading error!!! Probably your PDB file doesn't contain anything or poorly formatted\n");      
        return 0;
    }
    char test[255];
    while(!feof(pdb))
    {   
        fgets(test, 255, (FILE*)pdb);
        char check[4];
        strncpy(check,test,4);
        if(strcmp(check,"ATOM")==0)
        {
            fprintf(stdout,"%s\n",test);
        }           
    }
    fclose(pdb);
    return 0;
}

I was trying to use this code to retrieve the atomic coordinates (not the heteroatoms) from a PDB file by checking the first four letters of the line: whether they are "ATOM" or not. This didn't give out any warning or error during compilation but the output displays nothing. Nothing comes out as an output.

Can you please help?

pdb C • 3.6k views
ADD COMMENT
0

Login before adding your answer.

Traffic: 2389 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6