I am practicing my C++ programming just making an
Health Care related program, I cant seem to access
my data that is stored on a .txt file,
All I get is that f is not declared in this scope
Heres the code:

#include <iostream>
    #include <stdlib.h>
    #include "structr.h"

    using namespace std;
void regsPat();
void database(FILE * f);
void saved(patient ab);

      void menu(){
        int opc;

        cout<<"   ----<-<-<>--<-INOMO MEDICARE->--<>-->->----"<<endl;
        cout<<"        1. Register new Patient "<<endl;
        cout<<"        2. Database             "<<endl;
        cout<<"        3. Statistics           "<<endl;
        cout<<"        4. Corporate            "<<endl;
        cout<<"        5. Help          \n\n\n "<<endl;

               switch (opc){

                 case 1:

                 case 2:
                  database(f);//<------F WAS NOT DECLARED IN THIS SCOPE



As you can see im trying to access a external function
its in another file heres the code that im using:

void database (FILE * f)
{int a;
//float suma=0, promedio;
f = fopen("saved.txt", "r");

if( f == NULL)
printf("\nData Does not Exist! \nPlease Create it");

    fread(&ab , sizeof(ab), 1, f);
    if (feof(f))break;

    printf("Name: %d\n",ab.name);
    printf("Age: %s\n",ab.age);
    printf("Body fat: %s\n",ab.bodFat);
    printf("Height: %.1f\n",ab.height);


Recommended Answers

All 2 Replies

Why does the database function needs to be passed anything? From the looks of the function, all it does it use the "f" variable as a local variable, and it doesn't use its passed-value for anything. Just make it a local variable and make the database function a function without parameters.

The error is pretty obviously because "f" was never declared in the menu() function, just like the compiler says. You could declare a variable "f" in menu() and pass it to database(), but I see no point in that, because database() doesn't use that value.

Finally, if you want to practice your C++ programming, maybe you should try not to use C functions (like fopen, printf, etc.).

How do i pause output screen in c++?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.