0
I want to transform the whole process of input and output of the structure into functions, but I’m having problems with the result that returns, I believe it is something because the function is as void, I tested other types of data but there not even compile, can help me?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
typedef struct pc{
char cpu[25];
char gpu[25];
int ram;
int hd;
}Pc;
void ler(Pc entrada);
void resposta(Pc a);
int main (void){
Pc entrada;
Pc a;
ler(entrada);
resposta(a);
getch();
return 0;
}
void ler(Pc entrada){
printf("CPU:");
gets(entrada.cpu);
fflush(stdin);
printf("GPU:");
gets(entrada.gpu);
fflush(stdin);
printf("RAM:");
scanf("%i", &entrada.ram);
fflush(stdin);
printf("HD:");
scanf("%i", &entrada.hd);
fflush(stdin);
}
void resposta(Pc a){
printf("\nCPU:%s", a.cpu);
printf("\nGPU:%s", a.gpu);
printf("\nRAM:%iGB", a.ram);
printf("\nHD:%iGB", a.hd);
}
Study over pointers and use a pointer to the structure as a parameter in your reading function. Note that, as with any other function in C, the parameter is passed by value, this means that any changes in the structure made within the function will have no effect on the variable outside the function.
– anonimo