Chat Boss
Alex sent a code, it has been re-uploaded as a file
Light
Input Each test case consists of one line containing the message S, which has at least 1 and at most 100 bits. char n[???]; What is the correct array size here?
Ammar
depends if the bits mean the string bits, if so; it's 100/8
Just to expand on that. Since you can't have a fraction size, it needs to be rounded up and the scanf will put a NULL char at the end of the string, so ceil(100f/8) + 1.
Ammar
Alex sent a code, it has been re-uploaded as a file
Also, don't use scanf("%s", n);. You must have a defensive pattern when coding in C. That %s is vulnerable to buffer overflow. Use a limit like %32s (which only takes 32 characters), adjust with your need.
klimi
and normal curl works?
Light
why strlen showing wrong length ? #include <stdio.h> #include <string.h> int main() { char v[501] = "Pedro de Alcantara Francisco Antonio Joao Carlos Xavier de Paula Miguel Rafael Joaquim Jose Gonzaga Pascoal Cipriano Serafim"; int len = strlen(v); printf("%d\n", len); return 0; }
Leonardo
I created a program in C that encrypts a string according to an encryption algorithm when I have to replace a letter in the initial string that I want to encrypt with the letter of another alphabet string (where I saved all the letters of the alphabet) after calculating the index of the alphabet string that corresponds to the position of the letter that I have to replace to encrypt the first string, the program gives me a segmentation error and I don't understand why (I'm simply changing the letters of the starting string)
Anonymous
Input Each test case consists of one line containing the message S, which has at least 1 and at most 100 bits. char n[???]; What is the correct array size here?
The input is a string which is 100 characters long. Each character is a bit i.e. '0' or '1'. So you need an input array that is atleast 100 chars long for the input phase.
Hritik
hi can anyone help me with sum subset problem ? half tests passed in my code
Hritik
hi thank you ... but solved it ...sorry there was a small logical error
-
Hi I want to get the history of changes in a file . Is there any function which handles this ?
noalcoholatwork
Is it version controlled? Like with git or something? Other than that I don't think it's possible
Chat Boss
O sent a code, it has been re-uploaded as a file
(-__-)
O sent a code, it has been re-uploaded as a file
this code has no problems.. but if I write a++ in the line 28, then the compiler report a problem said "Cannot increment value of type 'unary' " .. Can anyone help my what is the difference??
(-__-)
++a is prefix increment a++ is postfix increment
yes .. but why is wrong to write a++ ?
klimi
yes .. but why is wrong to write a++ ?
because it is not implemented
(-__-)
klimi
post increment is more work since you need to make a copy of it and only then increment it
klimi
Can I know why🙂?
the same difference between prefix and postfix increment in iterators
Dm
Can I know why🙂?
You should overload operator++() And operator++(int) Check cpp ref for more info
Dm
++unary should return reference to obj. unary++ should return new unary object with state before increment
Null
sent by @dimazava Hello! I'm trying to implement move constructor and curious if one should nullify not only pointers, but "regular" types as well (such as int, bool, etc)? // Move Constructor Move(Move&& source) : data{ source.data } { source.data = nullptr; }
Anonymous
sent by @dimazava Hello! I'm trying to implement move constructor and curious if one should nullify not only pointers, but "regular" types as well (such as int, bool, etc)? // Move Constructor Move(Move&& source) : data{ source.data } { source.data = nullptr; }
You don't have to worry about primitive types whose destructors are a no-op. You will have to only worry about types with a destructor and pointers to heap allocated memory. You should leave instances of such types in a state where their destructors won't cause Undefined Behavior.
Anonymous
Hello everybody! Can someone tell me in 2 words what a c++ developer does? And why are knowledge of nosql databases and linux indicated in many vacancies?
Anonymous
is there sense to make reference to string_view?
Anonymous
is there sense to make reference to string_view?
No. A string_view can be thought of as being a fat pointer i.e. it is a pointer to a sequence of contiguous characters with an additional length field indicating how long the sequence is. Passing this by reference does not make sense because you don't want to impose an additional indirection at the caller site by passing it by reference. Also passing it by reference could imply a spill into the stack where previously a string_view could have been stored in a register. Passing it by reference also doesn't help the compiler's aliasing rules optimizations.
Light
#include <stdio.h> int main() { int cent = 70; printf("%.2f\n", cent / 100.0); return 0; } this program priting 0.70 How can I only print .70?
AlanCcE
#include <stdio.h> int main() { int cent = 70; printf("%.2f\n", cent / 100.0); return 0; } this program priting 0.70 How can I only print .70?
You have to change the calc to: printf("%.2f\n", cent * 0.01); I don't understand why your code already don't work, but maybe it's cause you typed cent as a int. so the division try to keep the value a integer at all, which removes the 7, making a multiplication like that seems to work
AlanCcE
But it still 0.70, i think he want to remove digits before .(dot)
You can try to format your output, try to search about the fprintf()
AlanCcE
Oops
Light
#include <stdio.h> int main() { int cent = 70; printf("%.2f\n", cent / 100.0); return 0; } this program priting 0.70 How can I only print .70?
Thanks everyone Here is the answer printf(".%02d\n", (int)((cent / 100.0) * 100)); I am not completely sure how it works but it works
AlanCcE
Alex Well, at this point you can just do that: printf(".%i\n", cent); You are making a division and a mult just to get the same value, its a little prolix code, but indeed works as well
Null
sent by @dimazava Hello, again Is there's a difference between following initialization lists notation? Which one is preferable? Per property, as commented line, and braced-constructor, as not commented line DataService(const DataService& someDataService) //: data(someDataService.data), someInteger(someDataService.someInteger) : DataService{ someDataService.data, someDataService.someInteger }
-
“Even though a member function declared in a class definition may be defined outside that class definition, that member function is still within that class's scope. ► If a member function is defined in the class's body, the compiler attempts to inline calls to the member function” can anyone explain these points to me?
-
Hi We can use FILE_ATTRIBUTE_HIDDEN as an argument in SetFileAttributes but how to unhide the file ?
dimazava
Hi We can use FILE_ATTRIBUTE_HIDDEN as an argument in SetFileAttributes but how to unhide the file ?
I suspect that you could get current attributes, check if hidden is there and apply bit operation AND to create mask, e.g. oldAttributes & ~FILE_ATTRIBUTE_HIDDEN
Anonymous
why my messages are deleted and resent by bot? According to rules several lines of code are ok
If you have many data members that need to be initialized, then initializing them in one constructor and delegating work to this constructor from other constructors is preferable. This makes your code more readable. Efficiency wise, there is not much difference as unlike other function calls, compilers are able to understand and optimize constructor calls better and both the cases that you showed will be optimised similarly.
Anonymous
“Even though a member function declared in a class definition may be defined outside that class definition, that member function is still within that class's scope. ► If a member function is defined in the class's body, the compiler attempts to inline calls to the member function” can anyone explain these points to me?
A member function defined inside the class body will presumably be in a header file and hence the member function body will be visible in all translation units that include this header file. Hence a compiler will be able to inline calls to this member function within those translation units. The primary requirement for inlining a function call is that it's definition be visible at the point where it is called. This is satisfied when a member function is defined within a class definition which itself is further defined within a header file. Modules in C++20 changes this however.
Anonymous
So it’s no difference, thanks
There is a difference from readability perspective.
Anonymous
Hi We can use FILE_ATTRIBUTE_HIDDEN as an argument in SetFileAttributes but how to unhide the file ?
``` int attr = GetFileAttributes(path); if ((attr & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN) { SetFileAttributes(path, attr & ~FILE_ATTRIBUTE_HIDDEN); } ```
Anonymous
why my messages are deleted and resent by bot? According to rules several lines of code are ok
If you send a particularly long message with code interspersed in it, the bot currently mischarecterizes it as a long code paste job and deletes it. Separating your code from regular text or using a pastebin site as suggested in the Rules helps avoid this problem.
Anonymous
C++ have some alternative to the Rust Docs or something similar?
klimi
C++ have some alternative to the Rust Docs or something similar?
cppreference is pretty good (don't know what rust docs are)
Anonymous
cppreference is pretty good (don't know what rust docs are)
This is exactly what I was looking for, thanks! =D
Anonymous
cppreference is pretty good (don't know what rust docs are)
They are the same. Rust docs document the API of a library crate or a binary crate. It is automatically generated from the documentation comments in your rust code. Cppeeference on the other hand is a wiki page edited by C++ developers by referencing the standard
Anonymous
It does. If your floating point number cannot be represented exactly and has an approximate representation with more than 2 digits after the decimal point, the code he listed ignores all of them except the first two. Having said that, the code is meaningless because as Anthony pointed out, he may have as well printed cents directly.
Roman
Which compiler should I use for a large cross platform project: clang or gnu?
Danya🔥
Which compiler should I use for a large cross platform project: clang or gnu?
Clang for sure - because there is a large cross platform project that's build only with the help of Clang - Google Chrome
Danya🔥
But my advise is not to limit yourself to one compiler and to make sure that you project is working with other compilers also - at least the 3 major ones - Clang, GCC and MSVC
Anonymous
But my advise is not to limit yourself to one compiler and to make sure that you project is working with other compilers also - at least the 3 major ones - Clang, GCC and MSVC
Just curious. Have you come across any instance where something works with one compiler but not with the other? I am not talking about features not supported by the compiler. Just talking about features that are supported by all. I use just GCC and Clang these days but I haven't come across issues related to a supported feature except for the fact that G++ produces a smaller binary and more often is faster than the one generated by Clang.
Danya🔥
Just curious. Have you come across any instance where something works with one compiler but not with the other? I am not talking about features not supported by the compiler. Just talking about features that are supported by all. I use just GCC and Clang these days but I haven't come across issues related to a supported feature except for the fact that G++ produces a smaller binary and more often is faster than the one generated by Clang.
Only one thing comes to my mind right now. In the summer of 2020, I had the amazing experience of being an intern at Intel. My project was to implement named requirements of the oneTBB library as C++20 concepts. All the compilers at the time claimed to support this language feature, but I noticed that one concept was handled differently in Clang and MSVC compared to GCC. This was a bit weird for me. I did some research by reading the C++ standard and talking to my colleagues, including one who was on the committee. They agreed that GCC's implementation was not correct. So, as a responsible engineer, I reported the bug to the maintainer and they explained that they had a different understanding of the standard and their approach was the correct one. You can check it out for yourself here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96821
Danya🔥
Just curious. Have you come across any instance where something works with one compiler but not with the other? I am not talking about features not supported by the compiler. Just talking about features that are supported by all. I use just GCC and Clang these days but I haven't come across issues related to a supported feature except for the fact that G++ produces a smaller binary and more often is faster than the one generated by Clang.
Also, recently at work we had a bug that was reproduced only in Android version of our software, which is build with Clang + libc++, but in x86 we use GCC + libstdc++ Basically the bug was dereferencing the first element of an empty std::vector. But it wasn't caught by GCC + libstdc++ with "lite" assertions enabled + ASAN (!) -- but only in Android built the app crashed even without the ASAN, in Release build.
Anonymous
Yeah, C++ standards as a good whiskey should not be "opened" for a while.
Hahaha. It would be well past C++26 when C++20 would have had enough time to mature. Modules is still a dark corner with people still confused about the global module fragment. Module partitions implementation is still broken. I would say regular modules use is still far away. That is what makes Rust more attractive to me. They let features mature on a nightly build and developers give constant feedback and then presto suddenly it is available on beta and stable versions. C++ is turning into a relic with all these issues.
Anonymous
I don't like Rust but I don't like C++ either.. Maybe even hate it.. I think ISO standardization process is not a good solution for a modern programming language. Maybe if C++ standardized by ECMA as they do with ECMAScript which is basically JS, thing would go smoothly..
The problem with C++ is that the standardization commitee is split from the implementation engineers (admitted that some of the engineers are there in the standards committee) and the regular developers. For programming languages like Rust, when a RFC comes in for a feature, as soon as it is accepted, the feature is added to a nightly build of the Rust tool chain. Developers use that along with the standardization committee members and constant feedback is generated and the feature matures and is made available in the next release. It is only after this process, the feature is documented into the next release version's documentation. Till this stage only the RFC is the go to document for the feature. For C++, this feedback loop is missing. The developers who use it are not part of the standards team and for a layman developer to give feedback on a proposed feature is a pain in the ass. Contrast this with the Rust Lang forum (which incidentally is the go to forum for Rust developers rather than Stack Overflow). Anyone can chip in and the feedbacks are seriously evaluated. Unless the mighty lords of the team overseeing the C++ standardization step down from their thrones, C++ is a language that will go the way of COBOL. Older systems will need support but new systems will look at other languages.
Anonymous
And the constant refrain from the standards committee to this complaint is "What prevents you from joining the standards team? If you want improvements join the committee". As if it were so easy. The process is a pain and people have to fork out 1000s of dollars to even see a meaningful change. No wonder they alienated people like Scott Meyers whose only fault was that he disagreed with some of the proposed features for constexpr and that he used the words "universal reference" instead of "forwarding reference" for which again he was chastised to the hilt