I am trying to write a function that will return a string to the main program. Basically, I am building a Perl-type hash in C to use zip code as my key and a string as the stored value. The function below is supposed to search the linked list and return the data string that is associated with the key.
Below is the function that I have now. The variable not_found is a defined as char not_found[] = "NOT_FOUND";. The structure is merely a linked list with 2 character variables and a pointer for the linked list.
How can I return a string to the main program without using global variables? How can I take the value in the main program and assign it to a string for output to a file?
Thanks.
Current Function:
int FindAS(char *zip)
{
struct linked_as_list *current_as_ptr;
current_as_ptr = first_as_ptr;
while ((strcmp(current_as_ptr->zip,zip) != 0) && (current_as_ptr != NULL)) {
current_as_ptr = (*current_as_ptr)->next_ptr;
}
if (current_as_ptr != NULL) {
return (current_ans_ptr->as);
}
else {
return (not_found);
}
}
Below is the function that I have now. The variable not_found is a defined as char not_found[] = "NOT_FOUND";. The structure is merely a linked list with 2 character variables and a pointer for the linked list.
How can I return a string to the main program without using global variables? How can I take the value in the main program and assign it to a string for output to a file?
Thanks.
Current Function:
int FindAS(char *zip)
{
struct linked_as_list *current_as_ptr;
current_as_ptr = first_as_ptr;
while ((strcmp(current_as_ptr->zip,zip) != 0) && (current_as_ptr != NULL)) {
current_as_ptr = (*current_as_ptr)->next_ptr;
}
if (current_as_ptr != NULL) {
return (current_ans_ptr->as);
}
else {
return (not_found);
}
}