How to read the last 3 characters of a char with no set size

1

I have a C application where I need to read only the last 3 characters of a char. Since the size of this char may vary, I did the following:

memcpy(valor_final, string_total[strlen(string_total - 3)], 3);

where valor_final will group the last 3 characters and string_total is my char all.

But this is returning me to the top three. Can someone point me the error?

    
asked by anonymous 09.06.2015 / 13:18

1 answer

1

You have a calculation error

memcpy(valor_final,  string_total[strlen(string_total - 3)], 3);
//                  v                                v   ^   |
memcpy(valor_final, @string_total[strlen(string_total) - 3], 4);

Do not forget to copy the terminator ( 'valor_final' ). Make sure you have space in %code% .

    
09.06.2015 / 13:21