Question: Reading atomic coordinates from a PDB file in C
1
gravatar for souparnoa91
22 months ago by
souparnoa9110
souparnoa9110 wrote:
#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?

ADD COMMENTlink written 22 months ago by souparnoa9110

Check this page. http://stackoverflow.com/questions/1453876/why-does-strncpy-not-null-terminate

ADD REPLYlink written 22 months ago by fishgolden280
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1757 users visited in the last hour