I'm currently writing a C++ program that reads in a text file and outputs certain things. So far, my program can read in the file then create a brand new file that contains the info from the first file (basically the new file is a duplicate of the first). Does anyone know how would I check for certain words or characters in the file? For example (several lines from the initial file):
SCALE3 0.0000000 0.000000 1.000000 0.000000...............
ATOM 1 N LYS A 2 -1.166 -1.878 1.710 1.00 0.00 N
ATOM 2 CA LYS A 2 -0.110 -1.837 0.660 1.00 0.00 C
These are three lines from the initial txt file. How would I do a check for the lines containing the word "ATOM" and print ONLY those lines to the output txt file. PLEASE HELP!!!
C++ programming?
what i would do is put
do {
c=fgetc(fname);
} while(c!='A'%26amp;%26amp;c!=EOF);
where fname is the FILE variable you put your file into. This would search the file for an A. if there is no A, then c would be EOF. After you put that code in, and there is an A in the file, put something like
if (fgetc(fname)=='T') {
if (fgetc(fname)=='O') {
if (fgetc(fname)=='M') {
// if the script in this if is read, then the line starts with ATOM
}
}
}
I'm not very good at explaining things, so i hope this helps. Good luck!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment