Below is a function returning a pointer to string, and this function is polymorphism, which means it could return any classmate's name.
const char* get_classmate_name(void);
Here is a task that asks you to put/get classmate's information into/from in info.txt under each classmate's folder, for example:
/good_class/Anderson/info.txt/
/good_class/Cindy/info.txt/
/good_class/Lily/info.txt/
I attempted to define those attributes with define macro:
#define CLASS_PATH "/good_class"
#define CLASSMATE_PATH CLASS_PATH##"/"get_classmate_name() //wrong
#define CLASSMATE_INFO_PATH CLASSMATE_PATH"/info.txt"
Obviously, the second macro is wrong because it's not allowed to concatenate symbolic constant, in this case CLASS_PATH, with const char* by using ## operator.
I want program to be simple such like
static bool folder_is_found(const char* folder_path);
int main(void)
{
if ((!folder_is_found(CLASS_PATH)) || (!folder_is_found(CLASSMATE_PATH)))
{
reutrun -1;
}
const char* classmate_height = get_classmate_height(CLASSMATE_INFO_PATH);
printf("classmate's height is :%s", classmate_height);
return 0;
}
How to correctly define CLASSMATE_PATH?
(!folder_is_found(CLASSMATE_PATH)))char buffer[PATH_MAX]; snprintf(buffer, sizeof(buffer), "/good_class/%s/info.txt", get_classmate_name())might be what you are looking for... Or print all three parts into format string"%s/%s/%s".