Query vector from one table to update another in C

Asked

Viewed 408 times

2

Hello. I’m new here and I’m not even sure I was objective in the title. But come on. I’m almost done with my final C Algorithms project, and I’m unable to update one item from one table with information from another.

More specific:

It is a program for scheduling medical appointments. I have a table of patients, doctors and appointments. Patient and doctor tables are working 100% (recording and alteration). My problem is in the table of appointments. Start the Save Queries module. The.id query is automatically generated. To choose the query.patient, I invoke the listBoxPatients for the user to select one of the patients and their name to be recorded in consultation.patient, pass the memory address to the outgoing pointer, then it receives the new content, When I return to the module of recording the consultations, the consultation.patient is not with the chosen name.

Follows the code:

typedef struct paciente{
    int cod;
    char nome[30];
    char sexo[1];
    char endereco[50];
} Paciente;

typedef struct consulta{
    int id;
    char situacao[2];
    char medico[20];
    char paciente[30];  
    char data[11];
    char hora[6];
} Consulta;


void gravarConsulta(){
    Consulta consulta;
   ...
    listBoxPaciente(consulta.paciente, 3); // carrega listagem de pacientes             
    gotoxy(12,13); printf("%s", consulta.paciente); // entra com o nome do paciente
   ...
}

void listBoxPaciente(char *saida, int carregar){
   Paciente novoPaciente[50];
   ...
   if (carregar == 3)   {
      saida = novoPaciente[y].nome;
   }
   ...
}

All I need to finish is to choose one of the patients from the.txt table and record queries in the table.txt. It is saved the last query.name you read when searching for the next query.id.

I hope someone can help.

  • The recording functionConsult is very extensive? You would mind posting it in full?

  • How do I post. Here only lets use 500 characters.

  • I posted on google drive:https://drive.google.com/file/0B7fBYLCTGkbdGJBcVlOMVVneTQ/view?usp=sharing

  • You may not be able to post links because you are a new user. Anyway, I guess I don’t need to see the rest of the code anymore (see answer).

1 answer

1


I think you meant

void listBoxPaciente(char *saida, int carregar){
   Paciente novoPaciente[50];
   ...
   if (carregar == 3)   {
      strcpy(saida, novoPaciente[y].nome);
   }
   ...
}

'Cause the way your code is saida is effectively a local variable; changing it will not affect the consulta in the other role.

  • Hello. Now it worked, but it is only passing the name, the surname is not going. Is it considering that space is the null character?

  • Probably the novoPaciente[y].nome is being populated incorrectly, but it is impossible to respond without knowing how it is filled. You are reading it from a file with scanf(" %s", …)? If so, see that answer here. If this doesn’t resolve, and you can’t find the error, it’s up to ask another question.

  • The patient file has n records. patient.name has size [30], but the content is variable in sizes. First I ask to read all the records and store in a new vector, newPatient with [50] positions. It is displayed on the screen in a list box, the user uses the cursor to choose one of the names. By pressing ENTER, the "output" variable receives the content of new.

  • This strcpy gave the same result. Just passed the name. Last name was not.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.