Code:
#include"stdio.h"
#include"stdlib.h" /*!! Use <> for system includes */
#include <string.h>
#define numloop 5000
#define helixsize 8
int main()
{
char hyphen = '!';
char atomname = 'H';
char u, r, l, d;
int t = 0;
int i, j, jj, ii;
int RESIDUES, CHAINS, natom;
int nuatom[2000];/*!! Consider putting these 6 variables into a struct */
int nures[2000];/*!! Also, make 2000 another #define constant */
char line[200];
char name1[2000];
char aa[2000];
char bb[2000];
char dna[2000];
char NAME[10];
FILE *out;
out = fopen("output.c", "w");
FILE *out2;
out2 = fopen("output2.c", "w");
FILE *in1;
in1 = fopen("outnames.c", "r");
int no = 0;
int fin = 0;
int test, num;
for (j = 0; j < numloop; j++) {
char q1[43] = "/home/Yazdan/dnabase/datadssp/1/";
char q2[43] = "/home/Yazdan/dnabase/datadssp/2/";
fscanf(in1, "%9s\n", &NAME); /*!! No & required, NAME is an array of char already */
strcat(q1, NAME);
strcat(q2, NAME);
FILE *in;
if ((in = fopen(q1, "r")) != NULL) {
printf("file is available here:%s\n", q1);
in = fopen(q1, "r"); /*!! it's already open, trying again won't help */
no = no + 1;
} else if ((in = fopen(q2, "r")) != NULL) {
printf("file is available here:%s\n", q2);
in = fopen(q2, "r");
no = no + 1;
} else {
printf("file is not available in sources\n");
fin = fin + 1;
continue;
}
for (i = 1; i < 30; i++) {
if (i == 7) {
fscanf(in, "%4d%4d", &RESIDUES, &CHAINS);
} else {
fgets(line, 150, in); /*!! in place of "150", use "sizeof(line)" */
fprintf(out, "%s", line);
}
}
natom = RESIDUES + CHAINS - 1;
/*!! Add a diagnostic check to make sure it's less than 2000-1 */
int n = 0;
for (i = 1; i < natom + 1; i++) {
/*!! I would suggest fgets() the whole line to begin with, then sscanf on that line */
/*!! rather than fscanf + some random fgets() to remove trailing data. */
fscanf(in, "%4d%3d%2s%2s%3s", &nuatom[i], &nures[i], &name1[i], &aa[i], &dna[i]);
fgets(line, 150, in);
if (dna[i] == atomname) {
n = n + 1;
}
}
int length = 0;
int k = 0;
int kk = 0;
/*!! consider making this a separate function to stop main getting too long */
for (i = 1; i < natom + 1; i++) {
/*!! you probably want || here, not | */
if ((dna[i] == atomname) | (dna[i + 1] == atomname) | (dna[i + 2] == atomname) |
(dna[i - 1] == atomname) | (dna[i - 2] == atomname)) {
length = length + 1;
bb[k] = aa[i];
k = k + 1;
if (length >= helixsize) {
if (kk == 0) {
for (ii = 0; ii < k; ii++) {
if ((t != 0) & (t % 75 == 0)) {
fprintf(out2, "\n");
}
fprintf(out2, " %c", bb[ii]);
t = t + 1;
if (ii == k - 1) {
kk = 1;
}
}
} else if (kk == 1) {
if ((t != 0) & (t % 75 == 0)) {
fprintf(out2, "\n");
}
fprintf(out2, " %c", bb[k - 1]);
t = t + 1;
}
}
} else {
if (length != 0) {
printf("length=%d\n", length);
}
length = 0;
k = 0;
kk = 0;
}
}
fclose(in);
fprintf(out, "\nno = %d\n", no);
} /*for number of loops */
fclose(in1);
fclose(out);
fclose(out2);
return 0;
} /*for main */
Then fix these warnings
$ gcc -std=c99 -Wall foo.c
foo.c:6: warning: return type defaults to `int'
foo.c: In function `main':
foo.c:37: warning: char format, different type arg (arg 3)
foo.c:39: warning: implicit declaration of function `strcat'
foo.c:7: warning: unused variable `hyphen'
foo.c:9: warning: unused variable `u'
foo.c:9: warning: unused variable `r'
foo.c:9: warning: unused variable `l'
foo.c:9: warning: unused variable `d'
foo.c:11: warning: unused variable `jj'
foo.c:31: warning: unused variable `test'
foo.c:31: warning: unused variable `num'