int main(void) { char tmp, arr[100]; int i, k; printf('Enter a string: '); scanf_s('%s', arr); for ( k = 0, i = (strlen(arr) - 1); k < (int) (strlen(arr) / 2); --i, ++k) { tmp = arr[k]; arr[k] = arr[i]; arr[i] = tmp; } puts(arr); return 0; }
I know that there is something weird about scanf_s() but I could NOT resolve the issue. My code works well by using scanf() but this does NOT reverse the elements of the array 🙁 Any help will be strongly appreciated. Thanks.
scanf_s requires the buffer size in chars to be passed as the second parameter.
You can also pass a width specifier. If passed and it does not fit into the buffer you will have only the first ‘width specified’ chars.