Reversing a string in C

If you want to practice advanced features of C, how about pointers? We can toss in macros and xor-swap for fun too! A pointer (e.g. char *, read from right-to-left as a pointer to a char) is a data type in C that is used to refer to location in memory of another value. In this case, the location where … Read more

How do I concatenate const/literal strings in C?

In C, “strings” are just plain char arrays. Therefore, you can’t directly concatenate them with other “strings”. You can use the strcat function, which appends the string pointed to by src to the end of the string pointed to by dest: Here is an example from cplusplus.com: For the first parameter, you need to provide the destination buffer itself. The destination buffer must … Read more

How to clear all the elements of array in C?

Your use of strlen() is wrong, that is reliant on the contents of the buffer being a valid string; it doesn’t clear the entire buffer. Just use memset() with sizeof: Note that sizeof is not a function, so no parentheses are needed (or should be used, in my opinion) for cases like these. If your C library doesn’t include memset(), a plain loop … Read more

Removing numbers from string

Would this work for your situation? This makes use of a list comprehension, and what is happening here is similar to this structure: As @AshwiniChaudhary and @KirkStrauser point out, you actually do not need to use the brackets in the one-liner, making the piece inside the parentheses a generator expression (more efficient than a list … Read more

Remove spaces from std::string in C++

The best thing to do is to use the algorithm remove_if and isspace: Now the algorithm itself can’t change the container(only modify the values), so it actually shuffles the values around and returns a pointer to where the end now should be. So we have to call string::erase to actually modify the length of the container: We … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)