eddyb wrote:My problem now is that i want to figure out some gets code (for commands)...
Your problem is that you lack
any decent programming skills. Time and time again you make the most basic stupid idiotic mistakes, bugging everyone with your crap. Let's analyze some of your code:
Code: Select all
while(text_m[strlen(text_m)-1] != '\n');
This is a while loop. That means it only terminates if some condition is met. That condition here is "text_m[strlen(text_m)-1] != '\n'". So if there's not a '\n' at the end of the string, the while loop never terminates. And if there
is a '\n' at the end, the while loop does exactly nothing, as it is an empty loop.
Code: Select all
memcpy(&text_ex, &text_m, strlen(&text_m));
text_ex and text_m are arrays. Arrays are already pointers. You should never precede them with an ampersand (and in case they are not arrays but char pointers, you take the address of the pointer, not the array they point too - recipe for desaster!). Furthermore, you are doing a memcpy, but use a strlen to determine the length. Why not use strcpy? You'd only not want to use strcpy if you do not want the terminating zero. However, look at the next statement:
That assumes text_ex is a zero-terminated string. (Yes, I know it's commented out, but the printf below has the same problem!)
Code: Select all
memset(text_m, 0, strlen(text_m));
Why do you not use sizeof(text_m) instead of strlen(text_m)? Of course text_m could be defined as an external and you do not know the size, but in that case use a #define that sets the buffer's length, to be used in both the variable declaration and the memset.
Code: Select all
printf("so, 1: %s\tso, 2:%s\n", &text_ex, &text_m);
Again, don't use an ampersand for text_ex and text_m as they are arrays (and, worse, if they are char pointers, you use the address of the char pointer instead of the pointer itself, which is desastrous). Also, text_ex is not guaranteed to be zero-terminated as you use memcpy instead of strcpy (see above), amd text_m is an empty string as you've just emptied it, so why print it?
You have thread unsafe code, as I bet text_ex is just a global, and not situated in the thread local storage?
text_ex is an export var.
There's no such thing as an "export var" in C. And please stop using all these stupid smileys.
JAL