I am working at the moment on a project that uses lots of arrays, yet I am not sure if I can use the <string.h> library functions: I need to save several product names in an array of strings in which the index is the product's ID. I dislike strcpy() because I am not sure if I can use the <string.h> library and even if I could, isn't it a bit annoying to print the name in a printf()? I am still considering that option but I am unfamiliar with it, maybe some insight would help.
char arg_description[63];
char *description[10000];
int product_id = 0;
int main() {
while (1) {
scanf("%s", arg_description);
description[product_id] = arg_description;
product_id++;
}
return 0;
}
This would be a replica of the code that is been bugging me. It's not the exact code, since the project is way bigger, but it represent the issue pretty well. It would appear to work at first, since description[0] would show the name of the product, that is if it would be only one product. It overrides the previous variable and even duplicates it. If the third product inserted would be bread, it would change the name of all the other descriptions to bread. And and I not even explain how strange this is to me. My qualifications are not the best, I am sure I am lacking skills, but I am here to learn.