c-strings Questions

3

Solved

In my Qt application my source code files are encoded as UTF-8. For the following code... QMessageBox::critical(this, "Nepoznata pogreška", "Dogodila se nepoznata pogreška! Želite li zatvoriti ova...
Horsemint asked 2/1, 2012 at 21:24

3

Solved

Code snippet: char str[] = "String1::String2:String3:String4::String5"; char *deli = "::"; char *token = strtok(str,deli); while(token != NULL) { printf("Token= \"%s\"\n", token); token=strtok(...
Alisa asked 24/4, 2015 at 12:47

3

Solved

Let's say I have a number of strings I use often throughout my program (to store state and things like that). String operations can be expensive, so whenever addressing them I'd like to use an enum...
Zetana asked 26/2, 2018 at 10:39

6

Solved

what should I use when I want to copy src_str to dst_arr and why? char dst_arr[10]; char *src_str = "hello"; PS: my head is spinning faster than the disk of my computer after reading a lot of t...
Pantia asked 8/8, 2011 at 19:4

6

Solved

I am really confused about the use of pointers on strings. It feels like they obey different rules. Consider the following code char *ptr = "apple";// perfectly valid here not when declaring afte...
Hoof asked 5/9, 2017 at 14:9

2

Solved

Consider the following code: constexpr auto f() { auto str = "Hello World!"; return str; } int main(int argc, char* argv[]) { static constexpr auto str = f(); std::cout << str << ...
Ambulance asked 28/7, 2017 at 6:54

3

Solved

I know %% is used to escape actual % signs in a string, so %%%ds will end up with %10s in the following format string, but I don't know why I need %%5s in this string? After all, there are only t...
Anytime asked 27/6, 2017 at 9:54

3

Solved

Do these two lines of code achieve the same result? If I had these lines in a function, is the string stored on the stack in both cases? Is there a strong reason why I should use one over the other...
Larrabee asked 29/10, 2010 at 11:28

3

Solved

The following program works fine, and I'm surprised why : #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> void xyz(char **value) { // *valu...
Sternutation asked 7/3, 2017 at 8:54

3

Solved

I Have some misunderstanding regarding this simple example: char *s = "abc"; s = "def"; Will the assignment of the second string cause a memory leak, or it will be replaced properly? If the form...
Unsuccess asked 14/2, 2017 at 9:48

1

Solved

I understand this is safe... const char *get_str_literal() { return "I literally can't even"; } But is this? const char *get_str_literal() { const char *str = "I literally can't even"; retur...
Diplococcus asked 2/2, 2017 at 4:16

1

Solved

I am currently learning vulkan. In one of the tutorials I saw a function which roughly does the following: #define SOMESTRING "Hello World!" std::vector<const char*> buildVector() { std::v...
Lammas asked 15/1, 2017 at 16:52

1

Solved

If I take the length of a string containing a character outside the 7-bit ASCII table, I get different results on Windows and Linux: Windows: strlen("ö") = 1 Linux: strlen("ö") ...
Afterward asked 24/12, 2016 at 1:39

5

Solved

So I just read an example of how to create an array of characters which represent a string. The null-character \0 is put at the end of the array to mark the end of the array. Is this necessary? ...
Turtleback asked 26/11, 2016 at 18:4

1

When overloading a method, I believe the compiler will choose the simpler match when multiple matches are available. Consider this code: #include <iostream> #include <string> struct ...
Eleonoraeleonore asked 24/11, 2016 at 3:9

1

Solved

The reason why I would want to do this is because I want to read from a file line-by-line, and for each line check whether it matches a regex. I am using the getline() function, which puts the line...
Jasso asked 17/11, 2016 at 0:4

1

Solved

I have a program that utilizes a Windows API via a C FFI (via winapi-rs). One of the functions expects a pointer to a pointer to a string as an output parameter. The function will store its result ...
Contumelious asked 16/9, 2016 at 15:5

3

Solved

I'm new in JNI so I'm not familiar in JNI and also English. My JNI project is a simple File reading and writing. File reading in Java and passing the byte array to C API the write it into file usi...
Propinquity asked 5/8, 2016 at 9:39

6

Solved

"One should always use std::string over c-style strings(char *)" is advice that comes up for almost every source code posted here. While the advice is no doubt good, the actual questions being addr...
Noni asked 5/4, 2012 at 3:1

2

Solved

We are transitioning C code into C++. I noticed that the following code is well defined in C, int main(){ //length is valid. '\0' is ignored char str[3]="abc"; } as it is stated in Array ini...
Barnhill asked 16/6, 2016 at 14:6

2

I want to find out why compare function doesn't give me correct result ? As I know it should return 0 if two string are the same! bool validatePassword(char id[], string password) { // cannot b...
Foliated asked 17/1, 2016 at 0:58

2

Solved

In c++11 array, string, and vector all got the data method which: Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is ...
Radio asked 8/12, 2015 at 12:1

2

I want to check if a MFC CString is null or not. Is there a way to do this? PS: I want to check if it is null not if it's empty. CString m_strName;
Presumptuous asked 24/11, 2015 at 9:53

4

Solved

While I was putting together a to-uppercase function in C++ I noticed that I did not receive the expected output in C. C++ function #include <iostream> #include <cctype> #include <...
Volant asked 12/10, 2015 at 16:33

1

I've written a DLL that creates an ATL CString object. I compile it with Visual Studio 2015 using the "Visual Studio 2015 - Windows XP (v140_xp)" platform toolset. The DLL is loaded using LoadLibra...
Lachesis asked 17/9, 2015 at 14:50

© 2022 - 2024 — McMap. All rights reserved.