I was using a string manipution function that uppercase the provided string //strupr();
But for unknown reasons I can't use pointer based string 🤔 like char *="all clear"; however char array works like char="all clear";
And when I combine both the methods it shows no output on sololearn ide.
Please help me to understand this . I used cxxdroid and c4droid also they give errors by both the methods (char * and char  ) saying that strupr not defined 🤔
Well in C we don't have string data type so we use char array or char pointers . So... should I even use char pointers for strings ? Because this is deprecated in C++ as per my knowledge.
< 12 sep 2019 code link removed adding code below >
char s1="All clear";
char *s2="All clear";
//uncomment above statements .
devanille very good solution 👌
Like it. //just don't like that I'll need to use loops.
Pointer based strings work with other standard string functions . But strupr isn't standard one (lately understood it's actually deprecated)
Thank you so much.
I'm not to sure, but I think it has something to do with the fact that string literals are immutable. Maybe, the strupr function modifies the string directly, but since a string literal is immutable, doing so will cause a segmentation error (no output in the playground).
If I'm not mistaken, strupr is part of POSIX library, so not all compilers can support it.
And, it's probably better to use string class in C++, but personally, I still use something like C-style string (char pointer and other things) because it's simpler for me, and it has become some sort of a habit
Android or Linux C compilers will give you errors because 'strupr' is a non-standard function from Microsoft. It works on SL because SL uses a Windows server.
I think there is no problem with the first string because you are passing the entire string to the strupr function, while in the second case, you are pasing a pointer (reference) to a string.
One possible solution:
Just a bit of advice, if you assign a string literal to a char pointer, like this one
char* str = "Some_String"
It's better (almost mandatory) to use const specifier
const char* str = "Some_String"
Like I said, something like that is actually immutable, some compilers will allow the absence of const specifier, but you will get segmentation fault anyway if you try to modify it. With the const specifier, you will get a compilation error instead of runtime error if you try to modify it or pass it to a function that will modify it
🇮🇳Omkar🕉 You're welcome. Thanks to you for your kindly words. And thanks Agent_I for the advice.
Btw, 'strupr' uses a loop internally: "The strupr() function replaces the string s with uppercase characters, by invoking the toupper function for each character in the string".