Hi,
I want to write a program to split one file into multiple files.
At any line that contains: "# Name:" i start writing to a new file.
My problem is that i want to save each file with a name i extract from the same line.
Example: # Name: C02427.mol TAUTOMER 1 2706
I would like to save this file as C02427_TAUTOMER_1_2706.mol2
Here is part of my code, i am stuck at the part where i put comments:
The problem is that these numbers are variable, so it can be :
# Name: C02427.mol TAUTOMER 1 2706
or
# Name: C02426.mol TAUTOMER 2
or
# Name: C02425.mol TAUTOMER 1 20
while(fgets (cbuff, 80, f1)!= NULL)
{
if (cbuff[0] == '#' && cbuff[2] == 'N' && cbuff[3] == 'a' && cbuff[4] == 'm' && cbuff[5] == 'e')
{
strncpy (name, cbuff+8, 6);
name[7] = '\0';
strcpy(filename, name);
strcat(filename,"_TAUTOMER_");
/*Copy characters from cbuff+28 to end of line and replace spaces with underscore */
strcat(filename, ".mol2");
fclose(f2);
f2 =fopen(filename, "w");
}
Any help will be greatly appreciated.
Thanks
Manali