!/usr
Yet
Anonymous
pastebin.com/JLtu4eGJ
Anonymous
pastebin.com/PKfTJyhD
Anonymous
Those are the two inputs
Anonymous
Hello guys, Must arrays be used always as parameters to functions or can I just use them directly in functions in the case where they are global variables?
Ihor
Hello guys, Must arrays be used always as parameters to functions or can I just use them directly in functions in the case where they are global variables?
If you have an array in your .c/.cpp file, and you want to modify it's values - then pass the arrays to functions by reference — the called functions can modify the element values in the callers' original arrays: void foo(int *ar, int N) { for(int i = 0; i < N; ++i) *(ar+i) = 0; } Or, yes, a global array can be called by any function, but in this case you must be carefully and choose the right way to organize you program. Simple and, may, bad code: int arr [3] = {1, 2, 3}; void foo() { for(int i = 0; i < 3; ++i) *(arr+i) = 0; } See these: 1. http://people.scs.carleton.ca/~dehne/projects/cpp-doc/tutorial/tut3-1.html 2. http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/declare-array.html
eric_maina
How is malloc() and calloc() used?
Hadaward 'Solly'
Vlad
How is malloc() and calloc() used?
https://en.cppreference.com/w/c/memory
Vlad
Thank me later
iski
Anyone have any link that they can refer to me that has solved a matrix in the form Ax=b by making the x matrix the subject and finding the inverse of A using C++?
Anonymous
/ban 1402591562
Anonymous
Which one do think is better? VSCode or sublimetext?
Anonymous
Which one do think is better? VSCode or sublimetext?
It seems VSCode is so popular... Everyone is using it. 🤷‍♂️ I haven't tried it even once.
Fabio🌲
Hey folks! I got a question: common sense says in header files we should only put declarations, but what if I want constexpr functions/methods in headers? I'm forced to write the implementation in there. Will this slow down the compilation eventually?
Anonymous
#include <iostream> #include <fstream> using namespace std; int main() { ifstream inData; inData.open("i.txt"); int l; int num; char k[31]; inData >> num; while (num != 999) { cout << num; for (l = 0; l < 31; l++) { inData >> k[l]; cout << k[l]; } inData >> num; } }
Anonymous
Why doesn't my sentinel work?
Fabio🌲
As I know it has nothing to do with the performance. Including headers is just like copying and pasting a file content. 🤷‍♂️
yeah but they get compiled in every unit they're pasted to, so compiling a declaration multiple times is way faster than compiling an implementation multiple times
Anonymous
Hey folks! I got a question: common sense says in header files we should only put declarations, but what if I want constexpr functions/methods in headers? I'm forced to write the implementation in there. Will this slow down the compilation eventually?
Not really There's also a term called header only libraries Generally the compilation times got slower only if you change the header a lot and it's included to a lot of files
Anonymous
It may slow down compilation times though if you have huge headers, I mean dozens of thousands of lines
Fabio🌲
so your suggestion essentially is "use constexpr definitions in header and forget all the fuss"?
Fabio🌲
oh, sweet! Sometimes simplicity exists in C++ :P I wish we've had modules sooner. It's unbelievable we had to wait for C++20 for such an essential feature nowadays
Anonymous
Well I like concepts more than modules actually
Anonymous
Or ranges...
Fabio🌲
keep the variable scope as smaller as possible
Anonymous
Anonymous
what are you asking? Please don't use forward declaration. This is not C
The problem is that once num is assigned 999, the loop does not terminate
Anonymous
Anonymous
Mr Danya, may I ask something?
Have you made anything useful in C++ yet or not? Is that possible to make something useful in C++ by yourself without wasting so much of your time?
Anonymous
Dontasktoask.com
Sry. Right. It wasn't an offtopic question I guess
Anonymous
Is money useful? I think so...
I've tried to use C++ many times, but each time I couldn't keep using this language. It's great, but really hard and time-consuming
Anonymous
I said maybe you've made anything useful using its frameworks
Anonymous
I like C++ because of its hardness
Anonymous
I like C++ because of its hardness
If you need to build some sort of small tool for yourself better use other language if you don't waste a lot of time to it and you don't like a lot of performance
Anonymous
Yes. Imagine a software for a web API. I've tried Qt, but again it's not that simple though 🤷‍♂️
Anonymous
C++ is hard, especially generic programming
Anonymous
Well, the code is meant to extract data from a file called i.txt whose content is( 1FFFFFFxxxxTTTTTTTxxxxFFFFTTTT999) And it wakes use of a sentinel controlled while loop. However, the loop continues indefinitely even upon reaching the sentinel value
Anonymous
I haven't not touched c++ yet but is c and c++ the same
Anonymous
I haven't not touched c++ yet but is c and c++ the same
No, it's two totally different languages that share some syntax
Anonymous
No, it's two totally different languages that share some syntax
Even in new C++ versions many things has changed in syntax. Let's say has added
Anonymous
https://twitter.com/mcypark/status/1352022455846506497?s=09
Anonymous
Just a news
Anonymous
Well, the code is meant to extract data from a file called i.txt whose content is( 1FFFFFFxxxxTTTTTTTxxxxFFFFTTTT999) And it wakes use of a sentinel controlled while loop. However, the loop continues indefinitely even upon reaching the sentinel value
Why not give it a line count or let it continue to EOF? #include <iostream> #include <fstream> #include <string> using namespace std; int main() { ifstream inData; inData.open("i.txt"); int rows; string line; inData >> rows; for(int i = 1; i <= rows; i++) { cout << "row " << i << " of " << rows << ": "; inData >> line; cout << line << endl; } return 0; } Reading a string type gives a whitespace seperated chunk of text.
Anonymous
if that's your input, there are not 31 values between 1 and 999, hence k[29] = 9, k[30] = 9 and num = 9
No, it is just a driver I am using to test a function in a code meant to mark answers. I need to properly extract a mixture of int and char values. That I do with the help of the sentinel loop where should 999 be extracted into the into variable, loop breaks and extraction ceases
Anonymous
Making things using pure C may end your life. I wonder how webserver like nginx have been made in C
Anonymous
I don't see any container there
Anonymous
Is that pattern matching?
That's what written there
Anonymous
if that's your input, there are not 31 values between 1 and 999, hence k[29] = 9, k[30] = 9 and num = 9
There are 30 char answers to be checked, extraction is done using a c_string and final element of the c_string must be a null character hence the reason for 31 size
Anonymous
Anonymous
wdym no? That's what happens with your input, num will never be 999
I tested it using cout and num becomes 999 at a point however the loop still continues
Victor D.
He means it for OS Development
Anonymous
+1 I agree
Victor D.
It's a fact that C has less overhead than C++
Anonymous
In the context of that flame some dufus was trying to overstep his authority and complicate the kernel build process...
Victor D.
It's a fact that C has less overhead than C++
In OS Dev you have to care about that
olli
I tested it using cout and num becomes 999 at a point however the loop still continues
that's simply wrong - if num were 999 it would stop and I even told you what's wrong
Victor D.
That's not true
Can you explain why?