Question: How do I get my function to print from elements.txt ( or any text file ) using pointers const char * classString; switch ( classChoice

How do I get my function to print from elements.txt (or any text file) using pointers const char *classString;
switch (classChoice){
case 1: classString = "alkali metals"; break;
case 2: classString = "metalloids"; break;
case 3: classString = "alkaline earth metals"; break;
case 4: classString = "reactive nonmetals"; break;
case 5: classString = "transition metals"; break;
case 6: classString = "noble gases"; break;
case 7: classString = "post-transition metals"; break;
case 8: classString = "lanthanides"; break;
case 9: classString = "actinides"; break;
case 10: classString = "unknown properties"; break;
default:
printf("Invalid class choice.
");
return;
}
FILE *file = fopen("elements.txt","r");
if (file == NULL){
printf("Error opening file.
");
return;
}
element tempElement;
while (fscanf(file,"%d %14s %2s %24s %lf", &tempElement.num, tempElement.name, tempElement.symbol, tempElement.elementClass, &tempElement.atomicWeight)==5){
if (strcmp(tempElement.elementClass, classString)==0){
printf("%d %s %s %s %lf
", tempElement.num, tempElement.name, tempElement.symbol,
tempElement.elementClass, tempElement.atomicWeight);
}
}
fclose(file); This is the code I am working with for reference

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!