Hi again,
I've progressed somewhat since yesterday and now have my .h files working half way.
I have been able to get the program to read from a file and then print to screen the data in the file.
The data is elements and their abundances.
Oxygen 65
Carbon 18
Hydrogen 10
Nitrogen 3
Calcium 1.5
Phosphorus 1.2
Potassium 0.2
Sulfur 0.2
Chlorine 0.2
Sodium 0.1
Magnesium 0.05
END
My task after this is to sort the data either alphabetically or numerically.
So far, the code for my .h file that handles this request is
Code:
int abundance_sorter() {
char string[100];
char fname[255], contents[255];
FILE *fp;
#define MAX 30
while(1)
{
printf("\n[Please enter the filename:]\n\n");
scanf("%s", fname);
/* Try opening the file. */
fp = fopen(fname, "r+");
if (fp == NULL)
{
printf("\nThe file '%s' could not be opened!\n\n", fname);
continue;
}
else
{
while (strcmp(contents, "END") != 0) {
fscanf(fp, "%s", contents);
{
printf("%s ", contents);
}
}
break;
}
}
//printf("%s", contents);
return 0;
}
If anyone has any tips on setting up an array for this and then sorting it, I'd be very grateful.
Cheers