I have a simple question.
Is it possible for a C variable to have a user-defined name?
Imagine this:
I have a function lets call it: create_new
It receives a string, lets call it: name[ ]
So the function looks like this:
char create_new(char name[ ])
My question is, can I use the characters in name[ ], to attribute a user-defined name to the string of chars that will be returned by the function. If not, how else can I attribute a user chosen name to a char string?

10 Years
Discussion Span
Last Post by Salem

Not sure just what you are asking Do you want the contents of the array name to contain some text that the user entered via keyboard ?

char name[80] = {0};
printf("Enter your name\n");
fgets(name,sizeof(name), stdin);
printf("You entered %s\n", name);

No, thats not really what I want. I want that the contents of variable name[ ], become the name of the char array that will be returned by function create_new, so that I have a different char array every time I call the function...


i can't for the life of me imagine why you would want to do such a thing.

but, admittedly, i'm getting old, and my neuronic sheaths are calcifiying....

struct uservar {
  struct uservar *next;
  char *userVarName;
  int userVarValue;

When you want to create a new one, allocate one of the above, complete the name (and value), and append to a list.
When you want to look up the user named variable, search the list.

etc etc.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.