Entering edit mode
7.8 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?
Check this page. http://stackoverflow.com/questions/1453876/why-does-strncpy-not-null-terminate