Assuming you now have something like this, you have another problem.
Code:
char *dbValue(char *codeValue)
{
t_asrepdb r_asrepdb;
t_asrepdb c_asrepdb;
char a;
int search_code;
search_code = search_dataCode(codeValue, &r_asrepdb);
if (search_code == -1)
{
}
fgets(c_asrepdb.value, 201, stdin);
a = strcpy(r_asrepdb.value, c_asrepdb.value);
return a;
}
Firstly, the fgets line should read something like
Code:
if ( fgets(c_asrepdb.value, sizeof(c_asrepdb.value), stdin) ) {
// success
}
1. Always test the return result of file operations.
2. Never use magic numbers to indicate the size of buffers. Always use a sizeof(), or the #define constant.
The return result of strcpy is the pointer you passed to the destination for the copy - namely r_asrepdb.value.
But r_asrepdb.value is just a local variable.
So when the function returns, the local variable no longer exists, and the pointer to the local variable is now an invalid pointer.
This will cause you problems.
The way out is to do something like
Code:
char *dbValue(char *codeValue, char *answer, size_t maxAnswerLen) {
}
In other words, you store the output string in answer, making sure to write no more than maxAnswerLen bytes to answer.