declaring 2d char array and passing through strings? [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Can someone explain what's happening in this line of code and how it's valid.
char output[][32] = {"Not present in trie", "Present in trie"};

It's declaring an array of n arrays of type char[32], where n is deduced from the number of initializers in the initializer list (in this case 2).
When the variable is initialized, the contents of the provided string literals are copied into the array (string literals can be used to initialize char arrays in C and C++).

Related

Problem with function printing random numbers when called. (C++) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 days ago.
Improve this question
This is what I have so far 1 When I call my function in int main, It prints infinite random numbers. I also have trouble with the array parameter and arguments. The question I am answering states "Create a program with a function that accepts three arguments: an integer array, an integer size that indicates how many elements are in the array, and an integer n . The function should display all of the numbers in the array that are greater than the number n."
I want the program to print out the numbers in the array that are greater than a number stated as an argument for the parameter N. Would really appreciate some help.

How to pass a string into glutCreateWindow() function? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am reading a name from a file which I then use to name the window. However, it will not allow me to do that since it requires an ASCII character string . I can however do something like this directly
glutCreateWindow("StackOverflow").
Isn't this also a ASCII character string? Why am I able to do this but not something like this:
string x = "stack";
glutCreateWindow(x);
Is there a way to cast "x" to meet my needs?
Use the std::string::c_str() method:
std::string x = "stack";
glutCreateWindow(x.c_str());

why addition using += operator is fast as compared to normal addition [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
str=str+(char)(newno+'0')
str+=newno+'0'
statement(1) is showing TLE whereas statement(2) does not.
The two statements are not at all identical. The first statement creates a new temporary string with newno+'0' appended, copies back the new string to str, and destroys the temporary object. The second can operate in place, if there is room in str.

Is it correct to fill sets contained in vector? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a vector<set<int>> v(10);. Each set can be filled by some data. Then I insert integers to randomly sets, e.g. v[5].insert(99);. Can it cause undefined behavior?
Only if you go out of bounds of the vector.
If your vector has at least 6 elements, then v[5].insert(99); is well defined.
To be sure that you don't, you can use the at accessor function:
v.at(5).insert(99);
Which will throw a std::out_of_range exception if you try to access past the end of the array.

why string concatenation getting strange result in c++? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am trying to concatenate two strings in C++:
"G1-2" + "-%02d.jpg"
and I am getting the following result:
G1-2-1537817269.jpg
Why isn't the result like this: "G1-2-%02d.jpg"
Wild guess!
You're printing the concatenated string by
printf(str);
where str is "G1-2-%02d.jpg"
printf("G1-2-%02d.jpg");
^^^^
// but, where is corresponding integer in the following?
As you can see there's a %02d in the string and printf will seek for a integer argument. It can not find it and undefined behavior occurs. In the best situation it prints out a random value with the string.
If my guess is true, then try to print the string in this form:
printf("%s",str);
or use double % as Chis mentined:
"G1-2-%%02d.jpg"