« first day (141 days earlier)      last day (2936 days later) » 

00:19
Could you suggest how to do that @schumacher574
@fsfh60 For starters, just remove everything related to grabbing the user input from this function. That behavior doesn't belong here. Plus, you already have the string t parameter to pass the string you're searching for into the function.

int find(vector<Person>& v, string t )
{
int length = v.size();
for(int i=0; i < length; i++)
{
if(v[i] == t)
{
return i;
}
}

return -1;
}
aha
@fsfh60 So all that is left is to grab the input from the user, call find(vectorName, userInput), and do something with the index it returns
@fsfh60 oh and of course change v[i] == t to v[i].lastName == t
I understand now.
For some reason all the outputs index is 0
can you post your code?
00:34
Ofcoures.
One second
00:46
@fsfh60
Ah - look at line 257, there is a key typo
@fsfh60 semicolons can cause unexpected behavior. In this case, your if statement has no body because a semicolon is immediately following it. Subsequently, the return statement will always execute during the first loop iteration (i=0).
@fsfh60 Depending on your compiler, it might spit out a warning - something like "suggest braces around empty body in an 'if' statement". Always check those, because they're often there for a reason
@fsfh60 I'm off. good luck
@sch
@schumacher574 Thank you!
01:11
Any one here can help me with a code ?
@fsfh60 If you look in the history books, you can find quite a few codes, such as those used to minimize Morse code transmission times. Entirely off topic here though--here we discuss code, not codes.
@JerryCoffin your awesome hahah
@fsfh60 Yore Kool two!
void remove(vector<Person>&v, string rnames)
{
v.erase(remove(v.begin(), v.end(), rnames), v.end());
}
What do you think is wrong with this code?
@JerryCoffin you there?
01:21
@fsfh60 remove wants an object of the same type as the target (apparently Person, rather than string).
@Mike I'm somewhere, I guess.
I want to ask why i need thread in c++? I know what is thread. But let me show you one code:
string get(argv[1]);

	std::cout << "Have " << argc << " arguments:" << std::endl;

	for (int i = 0; i < argc; ++i) {
		std::cout << argv[i] << std::endl;
	}

	cout << get.c_str() << endl;

	if (argc == 2 && get.compare("20") == 0)
	{
		while (1)
		{
			cout << "1" << endl;
		}
	}
	if (argc == 2 && get.compare("30") == 0)
	{
		while (1)
		{
			cout << "2" << endl;
		}
	}
I run this program with cmd pass different parameter. To different function. So same software but running two instance.
Is this two instance are two different thread?
@Mike Each instance is a process, which contains its own thread. That said, threading usually refers to multiple threads inside a single process.
@JerryCoffin Sir, so what is the different if i do same think with // Constructs the new thread and runs it. Does not block execution.
	thread t1(task1, "Hello");

	// Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution.
	t1.join();
@JerryCoffin Its mean before i running two process. But now if i use thread its mean one process two thread?
Guys, have you see a format string that has a "%%S"? If so, what does that mean?
oh wait nvm, looks like you use it to print a literal %....
01:36
seriously someone want help in his exam:
-5
Q: Can Anyone Code This in C++ Dos Fast Please?

PRinCe SaMiRPlease can anyone Code this for me In C++ as fast as possible .. check image .. (https://i.sstatic.net/9kSnB.jpg)

01:53
@JerryCoffin I am still trying to figure it out ?
void remove(vector<Person>&v, string rnames)
{
//v.erase(remove(v.begin(), v.end(), rnames), v.end());
}
 
3 hours later…
04:45
What does "a pointer to its associated buffer (if any)" meaning at the "7.21.1 Introduction" section in page 296 on C11 Working Draft Standard N1570? open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
1 message moved from Lounge<C++>
It states that
"7.21.1 Introduction
1 The header <stdio.h> defines several macros, and declares three types and many
functions for performing input and output.
2 The types declared are size_t (described in 7.19);
FILE
which is an object type capable of recording all the information needed to control a
stream, including its file position indicator, a pointer to its associated buffer (if any), an
error indicator that records whether a read/write error has occurred, and an end-of-file
indicator that records whether the end of the file has been reached; and"
Whats the exact question?
I interpret this to mean that the pointer can go to whatever the heck the implementation needs, and probably won't contain anything that a user can interpret without knowing implementation details.
Hey @milleniumbug How goes it ?
void edit(vector<Person> & v, string str)
{

   	int index = find(v, str);
    cout << index;
    for(int i=0; i< v.size(); i++)
    {
	    if(v[i].lastName == str)
		{
			Person aPerson;
			stringstream ss(str);
			string firstName;
			cout << "Enter the new first name: ";
			getline(cin, firstName);
			//str = firstName;
			string surname;
			cout << "Enter the new last name: ";
			getline(cin, surname);
			string birthday;
			cout << "Enter the new Date of Birthday: "<< endl;
			getline(cin, birthday);
Can some one please tell me what I am doing wrong ? I want to edit
I dont think I need aloop since I am only changing one person.
nvm I got it to work.
05:00
@Unknown123 It's whatever setvbuf is manipulating
05:27
void remove(vector<Person>&v, string str)
{
	int index = find(v, str);
	v.erase(v.begin() + index);;
}
@milleniumbug could you please help me correcting this function all I want to input string find the index and erase it .
05:38
@fsfh60 what is find
int find(vector<Person> &v, string & t )
{
   for(int i=0; i< v.size(); i++)
   {
      if(v[i].lastName == t)
      {
         return i;
      }
   }

   return -1;
}
and what's the problem again?
It's not erasing for some reason.
time to start up the debugger then
"7.21 Input/output <stdio.h> 7.21.1 Introduction
FILE which is an object type capable of recording all the information needed to control a stream, including its file position indicator, **a pointer to its associated buffer (if any)**, an error indicator that records whether a read/write error has occurred, and an end-of-file indicator that records whether the end of the file has been reached; and"

@Mikhail @milleniumbug
I'm asking what is the meaning of "a pointer to its associated buffer (if any)" in that context, how can a FILE structure contains a pointer of buffer, why must pointer? wh
06:11
@Unknown123 IYAM even though the standard wording is clearly normative by listing these, since there is no way to access these members directly (the standard doesn't describe the contents of FILE in terms of types and member names), these requirements could be disregarded by applying the as-if rule
in fact, thanks to 7.21.3.6 "The address of the FILE object used to control a stream may be significant; a copy of a FILE object need not serve in place of the original", I'm fairly sure struct _File {}; typedef _File FILE; is a legal implementation of this type.
oh, actually, no it's not, empty structs are illegal C
@milleniumbug
Thank you very much for your response, so i'm pretty sure it is implementation defined.

And then what does the words "its associated buffer" means? What does "its" refer to?

Does that "associated buffer" mean that every FILE structure will have a buffer?
so struct _File { char dummy; }; typedef _File FILE; then
@milleniumbug I can't figure it out :(
@Unknown123 Look at the full sentence "[...] all the information needed to control a stream, including its file position indicator, a pointer to its associated buffer (if any) [...]" (emphasis mine). So the stream has an associated buffer. Now let's see the wording in 7.21.3 where the buffers are mentioned
void remove(vector<Person>&v, string str)
{
     int index = find(v, str);

     if(index > -1)
     {
         v.erase(v.begin() + index);
     }
}
06:26
"When a stream is fully buffered, characters are intended to be transmitted to or from the host environment as a block when a buffer is filled."
^ there we have the distinction of unbuffered, fully buffered and line buffered streams, and there's a wording that links to setbuf and setvbuf functions
@fsfh60 have you actually checked the index returned is > -1
No.
so now you know where to start looking for
void remove(vector<Person>&v, string& str)
{
     int index = find(v, str);

     if(index > -1)
     {
         v.erase(v.begin() + index);
     }else
     {
     	cout << "Couldn't be found " << endl;
	 }
}
06:54
@milleniumbug
Thank you again, the language is very very formal, I must read it many times to understand it.

May I ask you again? Where does the location of stream and the buffer? does it has the same location?
@Unknown123 It's formal so people who implement C compilers know what they are expected to do. In particual, this is not the learning material.
If you want to learn C, get a C book
@milleniumbug
Thank you for your advice. I think it is the best thing ever to be learn. Because we can see directly the authenticity of the learning material which will be same across all platforms not just for windows or just for unix etc. Because I see some people just copy and paste without any source or quotation so I don't know if his opinion are valid across all platform or not.
@Unknown123 Fair enough. Just be aware that the wording is deliberately dense and precise and sometimes it requires "reading between the lines".
@Unknown123 If the standard doesn't say where it is, it pretty much means the decision is left to the people who implement the C compiler, and the environment they're programming against.
07:23
@milleniumbug I have understand thank you very much for your advice and attention
 
4 hours later…
11:40
Can I use const char** for creating char strings?
Hello
!
3 messages moved from Lounge<C++>
Ell
Ell
@MaxPayne that depends
Actually what does putting two stars mean? I mean const char *str = ... means a pointer to const char, which can be used to create arrays of char, if I am right. But what does const char** mean ?
I cant find it on the internet, mostly google.
this isn't the middle ages, std::string exists for 19 years already
and for that matter, std::vector too
@milleniumbug Yes sir I know, and I always like to use string everywhere, but In our school, we get questions to create arrays of char , arrays of string using pointers. And they mostly teach old C code as Cpp.
11:50
@MaxPayne const char** is a pointer to const char*
nwp
nwp
@MaxPayne Pointer to a pointer of chars. You have probably seen char **argv, which is essentially a list of strings. Or at least that is a reasonable interpretation.
Lets suppose I create an array of chars using const chat*. Then const char** will point to first char of the arrays of const char*?
oh it will not point to char will it?
nwp
nwp
no, the const char ** may point to the char *
363
Q: How do I use arrays in C++?

fredoverflowC++ inherited arrays from C where they are used virtually everywhere. C++ provides abstractions that are easier to use and less error-prone (std::vector<T> since C++98 and std::array<T, n> since C++11), so the need for arrays does not arise quite as often as it does in C. However, when you read l...

I get a bit, that means this is valid:
    const char *day1 = "Sun";
    const char *day2 = "Mon";
    const char **month = &day1;
12:04
yes, T* a; T* b; T** c = &a; is valid for any non-reference type T
The month is now pointing to the pointer day1, but how can I make a array of this without using []?
Actually I am sounding stupid but many times we get questions like this.
the month can be treated as if it pointed to an array of size 1
sure, if you want more elements, then no, you can't simply declare it that way like you did and expect month[1] to point at day2
Yes thats what I thought ! Thank you but how can I create an array of size 2, 3 etc. We must use the square bracket notation, mustn't we?
you point to the first element of the array, either named or anonymous
also you can get a pointer you can pass to old C style functions with std::vector<T>::data() if you have a std::vector<T>
This is working on my computer. Is this correct way:
    const char *day[2] = {"Sun", "Mon"};
    const char **month[2] = {&day[0], &day[1]};
    std::cout << *month[1];
Ven
Ven
12:54
&day[0] is a weird way to write day :P.
hello guys, in cpp are you separating business/ domain / data access? edited
Ven
Ven
what are you even writing
in separation i mean do you have separate class libraries for each layer and they communicate with each other
or you mostly have 1 library
or it depends on size of a project
nwp
nwp
the answer clearly depends on the problem you need solved
Ven
Ven
"it depends"
13:01
but its ok to have something like:
for e.g if we will use mvc pattern
I dont really know, just trying to make a array of string.
Model
- Header Files
- Source FIles
Controller
- Header files
-Source files
etc
how do you organize project
Ven
Ven
what are you trying to do...
nwp
nwp
Does your business logic require you to have Models and Controllers?
sometimes separation like that is a good idea, sometimes it's a horrible idea
13:05
@MaxPayne day is an array of C-strings
anyone got any cpp good sample project link?
Ven
Ven
github does, surely
13:38
I have another question , this time regarding inheritance.
Can derived class access base class constructors kept in public section? and derived publicly?
Ven
Ven
sure. usually in this case, you don't need to ask a question, it's easier to try it out for yourself.
We usually recommend using Coliru for any quick tests you may need to write – you just write code on the internet page and go!
Hello
Ven
Ven
it's basically a C++ (as well as many others) compiler available anywhere (... so long you have internet access).
So answer my Q :)
Ven
Ven
(I appreciate the hello, but please ask away :).)
I don't see a Q here :)
13:43
tell me where i can find CoolCtrls6.bpk and TMSC6.bpk?
borland c++ builder 6
Ven
Ven
yeah haha
lol
So...
I can't find them
nwp
nwp
are you being forced by some school to use that ancient borland thing?
:D
what i should use RAD Studio?
Ven
Ven
Qt Creator, CLion, emacs, vim, dunno?
nwp
nwp
13:48
You should at least use something that supports a recent standards compliant-ish compiler.
you don't know RAD Studio ?
nwp
nwp
possibly including visual studio
@Sami never heard of
Ok i'll show you
that what i'll use soon
Ven
Ven
why
nwp
nwp
13:51
@Sami less ancient, but still a weird exotic thing that nobody uses
Anyway , can you please answer my Q?
nwp
nwp
I'm afraid the people who know things about borland have died out.
Last Question promise!
Ok i understand
Why does this work? I did private derivation!
class Base {
	int x;
public:
	int y;
	Base() {
		x = y = 0;
	}
	Base(int num) {
		x = y = num;
	}
};

class Derived: private Base {
	int z;
public:
	Derived() : Base(5) {
		z = 1;
	}
	void fun() {
		std::cout << y; // Why this works
	}
};
nwp
nwp
13:57
because a class can access its private things
also Base::y is public
Ven
Ven
the y is public...
No but I derived privately
so shouldnt public things go private?
nwp
nwp
@MaxPayne that only means that Derived d; d.y; fails to compile
but from inside Derived you can still access y
if you make fun not a member of Derived you get the access violation
That means that whatever is in private of Base can never be accessed inside derived or by object of derived. But if something is in protected or public of Base, then on priivate derivation, it can be accessed from inside the Derived, but not outside it. Am I correct?
nwp
nwp
yes
14:08
Thanks Now i understood. :)
 
1 hour later…
nwp
nwp
15:31
@connormcwood you should put some code on coliru.stacked-crooked.com or ideone.com so we know what we are talking about
for example are you using find_if on an array of nodes or an array of pointers to nodes?
On an array of pointers which points to the nodes
And these nodes take in a KDT and a DDT. standing for Key Data Type and Data Datatype
nwp
nwp
ok, what does your comparison function look like?
@connormcwood you might want to spell that out, KeyDataType or Key_data_type so people can easier understand the code without prior knowledge
by comparison function I mean the predicate that find_if gets, which is not actually a comparison function
So far now I have only written the find_if statement. And I wanted to test it as I go through it as that is how I work. I am wanting the find_if method to find the Key Data Type.

I previously had it going through an iteration of the array and had a pointer returning each key but I was told I had to make my own implementation of find_if instead.
template <typename KDT, typename DDT>
Node<KDT, DDT>* Map<KDT, DDT>::find_if(Node<KDT, DDT>* first, Node<KDT, DDT>* last, KDT comparison){
	for (; first != last; ++first){
		cout << "This" << endl;
		if (comparison(*first)){
			return first;
		}
	}
	return last;
}
nwp
nwp
what is the comparison function?
where the if statement is? I need to write it but I am unsure how to go about doing it as apparently I need to make the comparison method be apart of the KDT datatype. So if for example KDT is a student(Name Grade) It needs to compare what is put in via the comparison parameter to the stored key.
Using templates do I use typedef to explcitly state how to deal with a certain condition such as KDT being a student and not an int because surely if not I would have to write a comparison function for any datatype I would like to use.

And if that is the case it is even less generic that me overloading the == operator with Name and Grade
nwp
nwp
15:41
there should be no typedef anywhere in the code
the function should look something like bool is_failed_student(const Student *s){ return s->grade == 'F'; } for finding a student who failed
The comparison operator for the class is not really needed because the predicate function internally figures out which student to find which may not involve comparing students.
I am wanting it to actually compare the data to what is already stored. So there would be an input in what is to be looked for and then that input would be compared with the students name and grade.
nwp
nwp
are you sure you mean find_if and not find?
This is how I was doing it but apparently it isn't allowed and is not generic.

//Initalises A Pointer So It Can Search The Node
		Node<KDT, DDT> *toSearch;
		//Loops Through The Array
		for (int i = 0; i < size(); i++) {
			//Sets The Pointer To The Arr Contents
			toSearch = arrOfData[i];
			//Condition In Which Is True IF The Return Key Method Of Node Is The Same As Key
			if (toSearch->returnKey() == key) {
				return toSearch->returnAddress();
			}
			/* x//Conidition Failed If No Match Is Found
Sorry I do mean find if I thought that was already established sorry.
The above code demonstrates that it iterates through the array and searches each node and returns it's key to be compared with the user submitted key
nwp
nwp
@connormcwood that is still ambiguous. find or find_if?
Find_if
15:51
hey I have a small question again:
void strcpy(char *dest, char *src) {
	while(*dest || *src) {
		*(dest++) = *(src++);
	}
}

int main() {
	char one[] = "Hello", two[1];
	strcpy(two, one);
	puts(two);
}
Why does it print the full string "Hello"?
two[] is of size 1 only!
nwp
nwp
@MaxPayne You are writing into memory you are not supposed to write to. It is undefined behavior, which may crash or do what you want or something else.
thats how strcpy was implemented right?
Ven
Ven
@MaxPayne who knows what's in two? not me.
nwp
nwp
Wait, ignore what I said about writing into memory, you have a strcpy that does something different.
regular strcpy does not have the *dest check
@connormcwood there should not be an exception thrown
@connormcwood also iterating with an integer only works for contiguous memory, but find_if should also work for things like linked lists
@connormcwood Wait, is that an attempt at implementing find_if or something else?
@MaxPayne no
The code I posted most recently was my find_if method but it was called find. Sorry about the confusion. I am wanting to search the stored data of the map for an element which matches the parameter given.

I've been told not to compare pointer->returnKey() == key as overloading == is not generic instead I need a comparison method in student to compare to right?
nwp
nwp
16:01
right, find_if is supposed to work on any range of objects and not all objects have a returnKey() function
However I am not sure how to implement this and I am unsure how me making this find_if method will effect normal datatypes such as int, double because they will not have a comparison method so my Ideas was to somehow explicitly state that if it is student use the comparison method
returnKey is a method in Node
The pointers in which I am using holds KDT key, and DDT data.
Sorry, I know you're gaping information and it can be hard to judge exactly what I am trying to do
nwp
nwp
@connormcwood if you need to explicitly state that you have a student it is not general anymore
@connormcwood you cannot assume that you have pointers to nodes, maybe you have just int
You see my issue. I do not understand what he means because I need to add a comparison condition to student so it knows how to deal with the find_if condition when it looks for a key.
But by doing this I would have to write one for each datatype I use. But this is still not generic so I honestly don't understand what should be done
nwp
nwp
what you do is you give a function to find_if that says if the element you are searching for is the current element
so you don't actually need to know how to compare elements, the function does
all you do is call the function and use the return value
23 mins ago, by nwp
the function should look something like bool is_failed_student(const Student *s){ return s->grade == 'F'; } for finding a student who failed
and then you say auto found_position = find_if(students[0], students[0] + students.size(), is_failed_student);
How should I set up the parameters and such in terms of the is_failed_student parameter
nwp
nwp
16:08
and then found_position either points to the end, which is students[0] + students.size() or it points to one of the students where is_failed_student was true, so a failed student.
@connormcwood template <class Predicate>
maybe your prof prefers template <typename function> instead
I've just clicked on about template functions,
Okay I think I understand a little. Within the find_if statement I iterate through the array using the begin() and end() method I created however when I display the contents of what the addresses are the values do not match up.
nwp
nwp
usage should look something like this
//Begin Const Iterator. Read Only Iterator To Give Starting Position Of Array.
Node<KDT, DDT>* begin() const {
return arrOfData[0];
}
//End Const Iterator. Read Only Iterator To Give Ending Position Of Array.
Node<KDT, DDT>* end() const {
return arrOfData[0] + curr_size;
}

Output:
00E86FA0 (First element)
00E81510 (Second)

Node<KDT, DDT>* Map<KDT, DDT>::find_if(Node<KDT, DDT>* first, Node<KDT, DDT>* last, KDT comparison){
for (; first != last; ++first){
cout << first << endl;
}
return last;
}
Thanks and I would put the templated condition in main
well actually whever the if statement is, I think I understand a little more
nwp
nwp
I understand that you have a Map m; somewhere which is your custom Map. We can say m.begin() and m.end() which gives us proper iterators. So far so good.
The second part I don't understand. Why is find_if part of the Map?
It should be a normal function outside of Map.
Unless the assignment says otherwise.
I don't think it says anything regarding where it should be, I just thought it makes sense being in there and being a method of map?
nwp
nwp
16:22
Well, if it is part of Map you can only use if for Maps. If you make a Array you have to write it again. So it would be more general if it was outside of Map and would work for any container that has a begin and end.
The assignment is only about our own custom map. So creating the method within the map is fine I think.

I have many instances of map which takes many types of datatypes such as int, int.

double, student. ect. The assignment is more focused on the map and its methods. However apparently I wrote the find method in a non generic way
nwp
nwp
if it is part of the Map there is no need to give it iterators, it can just call begin() and end() by itself, so you only need the function as a parameter
template<typename KDT, typename DDT>
bool Map<KDT, DDT>::is_condition_matched(Node<KDT, DDT>* address, KDT comparison){
	return (address->returnKey() == comparison);
}

template <typename KDT, typename DDT>
Node<KDT, DDT>* Map<KDT, DDT>::find_if(Node<KDT, DDT>* first, Node<KDT, DDT>* last, KDT comparison){
	for (; first != last; ++first){
		cout << first << endl;
		if (is_condition_matched(first, comparison)){
			cout << "Found It" << endl;
			return first;
		}
	}
	return last;
}
I think you've helped me succeed, the only issue I have now is that the iteration does not iterate the right amount in terms of addresses
nwp
nwp
Since you are iterating over an array of pointers they should be 4 or 8 bytes apart. Are they not?
They do not seem to be. 01136FD0, 01131510. They are initalised like this: Node<KDT, DDT>** arrOfData = new Node<KDT, DDT>*[max_size];

That means an array of pointers correct?
16:34
@MaxPayne Undefined behaviour is undefined
Actually it must be because it is an array of pointers of node not an array of pointers pointing to each node
So node has its datatypes which increases the size
nwp
nwp
what is arrOfData?
Hi guise
Is there a way to type erase a member function
nwp
nwp
std::function should work
Nope because I would like to handle different signature
lemme show you some sample
16:39
arrOfData is the array of pointers
nwp
nwp
seems to do what you want
Not exactly but that doesn't matter, my idea sucked anyway
I wanted type_erased_t_member_func to handle various signatures
eg T::foo(int), T::bar(double, double) and so on
Should I change the data type of Node so that KeyDataType and DataDataType both create another class and would this keep all instances of node at the same size?
nwp
nwp
@connormcwood is it important that all nodes have the same size?
16:48
So I can iterate through using begin() and end() instead of going through index?
nwp
nwp
using begin() and end() should work just as well unless you do funky casts
I use

for (; first != last; ++first){
cout << first << endl;
if (is_condition_matched(first, comparison)){
cout << "Found It" << endl;
return first;
}
}

And it iterates many addresses before it finishes
@Rerito Boost.TypeErasure defines a std::function-like type which can handle multiple signatures boost.org/doc/libs/1_56_0/libs/type_erasure/example/…
@milleniumbug nice! thanks
oh, actually it doesn't, but that's how you could implement it ^^
nwp
nwp
16:51
@connormcwood I don't know, it should just work. You could use a debugger and go through it step by step to see if it looks at the right addresses in the right order. I have no clue how many addresses it should be looking at.
There should only be three as there is only three elements in the array
nwp
nwp
@connormcwood But it does look like you don't return anything when you didn't find a match, so maybe that is it.
Should it not iterate through only the pointers stored
nwp
nwp
it should
17:13
HEy guys is there a work around this error ? I am using a switch statement.
[Error] jump to case label [-fpermissive]
I am back
void strcpy(char *dest, const char *src) {
	while(*src) {
		*dest++ = *src++;
	}
}

int main() {
	char one[] = "Hello", two[6];
	strcpy(two, one);
	std::cout << two;
	//puts(two);
}
Here I have a big doubt
Look : std::cout << two prints 'Hello' twice! but puts(two) prints once!
Why cout prints the string twice?
nwp
nwp
your strcpy is still not correct because it didn't set the terminating '\0'-character in dest
        case 'R':
        	int length = v.size();
    		if (length < 1)
			{
        	cout << "Nothing to display" << endl;
    		}
			cout << "Enter the last name to find and remove" << endl;
			getline(cin, name);
            remove(v, name);
            break;
ok I will deal with it, but why cout is printing it twice?
lets fix the null.
17:18
@MaxPayne Undefined behaviour is undefined
whaat?
is that
why is that undefined?
Whats going on? I added null terminator and it works now!
void strcpy(char *dest, const char *src) {
	while(*src) {
		*dest++ = *src++;
	}
	*dest = '\0';
}

int main() {
	char one[] = "Hello", two[6];
	strcpy(two, one);
	std::cout << two;
	//puts(two);
}
nwp
nwp
@MaxPayne because puts and cout read two until they find a '\0', but they don't, so they start reading memory you are not supposed to access
Nov 12 at 21:23, by milleniumbug
@BIG-95 strlen works by looking for the first occurence of '\0'. Guess what happens if it doesn't find it before the array ends
^ replace strlen with std::char_traits<char>::length() and you have your answer
@milleniumbug I got it thanks.
ok now I get it. But what happens if dest is smaller than src?
How can we modify the program for that?
17:23
@MaxPayne Undefined behaviour
nwp
nwp
@MaxPayne Use std::string and forget about all the problems.
We cant know the size of array from the pointer right?
no you can't
True its a complete headache
I guess dest must have to be larger than src.
One last question and I wont irritate you again!
void strcpy(char *dest, const char *src) {
	while(*src) {
		*dest++ = *src++;
	}
	*dest = '\0';
}

int main() {
	char one[] = "Hello", two[3];
	strcpy(two, one);
	std::cout << two[4];
	//puts(two);
}
Here, look at second last line.
@MaxPayne Undefined behaviour
17:26
two is of size 3.
how can we access two[4]
@milleniumbug is that undefined? I thought compiler would show error! (g++)
@MaxPayne [defns.undefined] "undefined behavior - behavior for which this International Standard imposes no requirements"
> Permissible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).
@MaxPayne It can't issue a warning in every case you do something wrong (for example when the index is actually a variable which is read from file). In this case it actually does if you enable warnings coliru.stacked-crooked.com/a/be6322fb1670439c
PSA: Enable warnings in your compiler if you haven't already (in gcc: -Wall -Wextra -pedantic)
14
17:55
ow
Thanks for the information
I didnt enable the warnings
I mean I used it as it was by default.
18:07
Creating a == operator overload for a particular class is considered not generic right so how would I go about doing a comparison with a class which doesn't have a == operator
nwp
nwp
18:18
@connormcwood bool operator ==(const MyClass &lhs, const MyClass &rhs){ return something; }
or a generic function bool same_something(const MyClass &lhs, const MyClass &rhs){ return something; }
:34322667 I've currently got

//Takes In The Given Value And Compares It To The Objs Actual Real Value For Both Variables
bool operator==(const student& os, const student& obj){
	return (os.getGrade() == obj.getGrade()) && (os.getName() == obj.getName());
}
That is not generic correct
nwp
nwp
18:36
@connormcwood why not?
can be made a bit prettier with std::tie, but other than that it doesn't get much better
so there is no issue with my implementation? Maybe I misunderstood my professor. Thanks for helping me out earlier by the way, do you do this as a job?
nwp
nwp
I write software as a job and hobby.
sometimes it even works
You must be very passionate about it to spend your free time helping others. You should teach people via sites such as YouTube and maybe make some money from it. Have you thought of that?
nwp
nwp
19:01
I did some twitch streaming. It didn't work so well, concentrating on other things while programming is hard.
19:24
I suppose. Could you help me with my logic. Once an element is deleted I want to iterate through the array after the index of the deleted element so I can push back each element to reduce the size of an array.

    		int keyIndex = find_if(0, size(), key);
    		for (int i = 0; i <= size(); i++) {
    			if(size() != 1){
    				for (int j = keyIndex; j < size() - 1; ++j) {
    					arrOfData[j] = arrOfData[j + 1];
    				}
    				//Reduces The Size Of The Array
    				curr_size--;

    			}
nwp
nwp
I don't understand why you have different cases for size() == 1
So when it is completely empty the first element is set to null
@nwp If it started out as only one element, he can skip over the loop to copy the remaining elements. I agree, however, that it would be cleaner to just execute the loop N times, where N might be equal to 0. Setting arrOfData[0] to 0 is basically pointless, and skipping it shouldn't mean anything, assuming the rest of the code is halfway sane (i.e., when size == 0, you should never even look at the "contents" of the array).
nwp
nwp
what is the outer for-loop for?
@nwp To turn a user's request to delete one element into actually destroying the entire array, obviously.
19:36
I think it was left from my attempt much earlier in the methods timescale. However removing it has seemed to fix it
nwp
nwp
@connormcwood where do you get the data from? Are you allocating the nodes with new and then not delete them?
I was deleting them prior to me updating the erase method
 
2 hours later…
21:58
Hello
I have a regex function which search in <head> all hreff from here </head>
<head.*?>([\s\S]*?)<\/head>|(href=["\']?([^"\'>]+)["\']?)
Problem is search href after </head>
4 messages moved from Lounge<C++>
@IsabelCariod You know the stock response, right?
4426
A: RegEx match open tags except XHTML self-contained tags

bobinceYou can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML. As I have answered in HTML-and-regex questions here so many times before, the use of regex will not allow you to consume HTML. Regular expressions are a tool th...

what is stock response
@IsabelCariod What does that mean, in the first place. Have you considered using github.com/google/gumbo-parser or something like crummy.com/software/BeautifulSoup/bs4/doc
@IsabelCariod It's the standard answer. "Stock articles" are the shopping articles which are always available in the store and suit 99% of the needs.
@IsabelCariod A response related to livestock (horses, cattle, etc.)
nwp
nwp
22:09
@IsabelCariod That doesn't actually help you through. You can put your regex into sites like this and play with it until it does what you want.
@JerryCoffin oh you
why convert link?
@JerryCoffin what's the link?
@IsabelCariod The sole linkage is through my warped mind... :-)
how can I send you a link?
@IsabelCariod You can post links here, if that's what you're asking.
nwp
nwp
22:17
@JerryCoffin Are you a Malkavian from Vampire the Masquerade?
(you don't need to answer if that saves you masquerade points)
@nwp My vampirism is no masquerade.
href's in <head></> shoud be selected
Seriously, this is the first time I've even heard of "Vampire the Masquerade".
nwp
nwp
you should play or watch it, it is quite fun
22:31
@nwp Hmm...thanks, but I think I'll pass at least for now.
1. don't use regex
2. really, don't
...
3. still here? Ok. Do a two-phase. Select `<head>.....</head>` first (that's "simple" (cough, beware of the XML specs!) `<head[^>]*?>(.*?)</head\s*>`, make sure to be case-insensitive, say good-bye to namespace qualified XHTML elements)
4. search the refs in the result of 3.
ROFLMAO I had totally forgotten about this. That should REALLY convince you not to mix HTML with regex
23:42
@sehe "ware the ides of tags."

« first day (141 days earlier)      last day (2936 days later) »