I am using sscanf in my project to copy strings from source buffer to target buffer. For example:
char* target;
target = (char*)malloc(100 * sizeof(char));
char* source = "Hello World";
sscanf(source, "%[^\t\n]", target); // trying to copy "Hello World" into target.
printf("%s\n", target);//this will print "Hello World".
But this way of coding style is not accepted. What my manager want me to do is something like:
sscanf(source, "%11[^\t\n]", target); // NOTE: I've written "%11". here, 11 == length of hello world.
That means, he want me to provide format specifiers as well. (%11 in this case).
But, the problem is that source can be of varying length and I don't know how to write the correct format specifier for every varying length string.