Code:
printf("\n\n Name the Prop. Percentage output file (12 chars max): ");
scanf("%s", output);
Rather than doing that, consider using fgets(). This would also help if you had a filename with a space in it, for example. Your current code would not handle that very well.
Code:
fileptr = fopen(output,"w");
You never close this file. It's best to close files when you're done with them. They are automatically closed with most modern operating systems when your program exits, but you have problems if you try to open the file again, or the file is modified by another program, etc. Just close it when you're done. It's just one line.
Also, an observation:
Code:
for(int i=1;i<=num_prop; i++){
sprintf(dirname,"%d",1000+i); // this is just a numbering standard
// the folders start at 1001
chdir(dirname);
fileptr = fopen(name, "r"); // open the file with the constant name
// since all folders have one file of this name in them
/*the loop which is giving me issues */
while (fscanf(fileptr,"%f", &tmp2) != EOF) {
printf("\n\nIncrementing Particle %d", tmp2);
arry[(int)tmp2]=arry[(int)tmp2]+1;
}
fclose(fileptr); // close the file
chdir("../"); // navigate back out to master folder
}
You're calling chdir() twice. It might be more efficient if the first chdir was "1001", succeeding ones were "../XXXX", and the last chdir was "..". Your code would execute the same way but would call chdir() less often.
Also, why do your folder numbers start at 1001 and not 0001? If you were having problems adding the leading zeros with sprintf(), use a flag like this:
Code:
printf("%4d", 1); /* prints "0001" */