« first day (581 days earlier)      last day (2496 days later) » 

10:44
@sehe I'd say the book choice depends on what you're going to use C++ for?
Not really.
The basics can only be learned badly or well.
In that case, I vote for the Primer as it contains more details than the Accelerated.. if I recall correctly
@iksemyonov Because, what you say only makes me think of books like "C++ for Game Developers". And that mostly makes me want to puke.
@iksemyonov Could be, don't really know it.
I think there's the problem that there are many "Primer" C++ books, and some of them are Bullschildt
(IIRC/ICBWT)
@sehe "The C++ Primer 5ed" by Lippman, Lajoie, Moo.
@sehe I compared them briefly a while ago, and 1) Accelerated doesn't cover cpp11; 2) it seems to skip many details.
Skipping details is Good(TM). Not covering cpp11 is a shame, but not necessarily a stopper for learning the language basics.
In fact, I'd argue that a good book teaching cpp11 should take the opportunity to skip a lot more details.
10:54
If things like promotions, conversions, and arithmetic are the basics, then I think The Primer does a better job.
Though the wording between it and the Standard is slightly different and for a guy like me, that's a bit of an obstacle.
@iksemyonov usage of smart pointers and why rule of 0 is best rule is also part of basics
Yep, that is what I'd focus on first, too.
I mean the details are nice, but I'd merely warn about the dragons ("beware of contagious unsigned and, legacy-C-compatible implicit conversions (-Wimplicit* -Wconversion*)") instead of teaching the nitty-gritty as if they were the most important
@sehe With conversions, I mean "which arithmetic type gets converted and / or promoted to which one, how are overloads resolved for arithmetic types" - that kind of thing that you often get to see in C++ tests.
Fuck C++ tests?
it's also the same for basically every language
11:04
In reality, people use programming languages to write programs. It is objectively more relevant for people to know how to organize data structures and logic, and how the standard library helps with that.
Thus, you recommend to pay more attention to the higher-level features that make C++, C++.
Correct?
Certainly for the "intro" book, yes.
user6685907
11:51
guys can i ask for help?
user6685907
Error 12 error LNK2019: unresolved external symbol "class osdp_hub * __cdecl create_osdp_hub(void)" (?create_osdp_hub@@YAPAVosdp_hub@@XZ) referenced in function "private: static void * __cdecl dcp_core::core::thread(void *)" (?thread@core@dcp_core@@CAPAXPAX@Z) C:\Users\Stephen\source\repos\OldSensurityCo‌​nfigurationTool\halo_dcp\core.obj libdcp
user6685907
this class is located in another project that is referenced in the current project
3 messages moved from Lounge<C++>
12:06
1094
Q: What is an undefined reference/unresolved external symbol error and how do I fix it?

Luchian GrigoreWhat are undefined reference/unresolved external symbol errors? What are common causes and how to fix/prevent them? Feel free to edit/add your own.

@sehe In that case I should note I'm relearning C++ from scratch after having been familiar with it for a few years, and this time around I'm going through the details on purpose.
Oh yeah. We all did.
I reckon, if you don't, you'll leave C++ pretty soon
@sehe Why, I'm intending to get a job in C++ .. and that's my main point in the CV anyway :D
:shakes-hand:
While we're at it. Here's one, to quote the `Primer`:
> "When we assign a floating-point value to an object of integral type, the value is truncated. The value that is stored is the part before the decimal point."

Is this really correct? I've come across that problem, and in my implementation, `float` to `int` assignment used banker's rounding. The `truncf` intrinsic was required to achieve reliable truncation.
12:21
assigning floating point to integral is a compile error
nwp
nwp
It's clearly not correct for floats that are too big to fit in an int and nans.
@ratchetfreak What? I thought we were talking about int i = 3.14; which compiles fine.
@nwp Well, let's assume it fits. And we use a static_cast<int>().
nwp
nwp
Then it should be correct. Do you have an example where it produces an unexpected result?
Not an SSCE, no. But I could see the effect in my program (though graphical) from switching to an explicit truncf. Maybe it's worth saying that the compiler wasicc with O2 or O3.
But I can find an article an a minute, that stated: banker's rounding is used by default.
I guess not...
I guess I'm too used to java where float to int assignment is a compile error
nwp
nwp
12:27
@iksemyonov Maybe that implicitly turned on --ffast-math which gives the compiler permission to do some shady fast but not quite correct optimizations.
For starters, there are 3 rounding modes, so can I say that float to int assignment uses one of those, and not "truncation"?
@nwp I've thought about fast math, too. Looks very much like it. To be sure, I need to check the assembly, indeed.
nwp
nwp
The standard agrees with the quote, so if you find an implementation that differs you should file a bug report.
truncf Computes the nearest integer not greater in magnitude than arg which is different, so different results for your graph are to be expected.
At least I think it's different.
Actually it looks the same. I don't know why there is a difference.
And here I thought C and the preprocessor didn't support templates.
there is a type based selection mechanic in the preprocessor
12:42
@iksemyonov Do you have anything better to offer than inscrutable anecdote? ^
@iksemyonov I call bullshit. Or, to put it more mildly: observer error/assumption fallacy
@iksemyonov You can say whatever you want. What does it matter?
@sehe OK, enough fun :p Does the standard guarantee that a float to int assignment will behave as a mathematical truncation (I'm not saying a word about the implementation, of course.)?
14 mins ago, by nwp
The standard agrees with the quote, so if you find an implementation that differs you should file a bug report.
Oh, pardon me, AFK. Reading @nwp answer.
See what I'm getting at here? This kind of detail-fetish leads to heaps of confusion. Imagine what happens to total noobs
12:51
I know. I also know teaching is damn hard exactly for that reason, having to know where to draw the line.
@sehe as far as fuck tests. Then you have to do the same to interviews. These details do pop up from time to time.
nwp
nwp
@ratchetfreak That's pretty cool. I did not know that existed.
It really depends on the problem domain, I think. See embedded, for example.
@iksemyonov Oh, I'm all in favour of knowing the details.
But I'm not ashamed to say "I always look this up". Or "This is what I write tests for"
nwp
nwp
@iksemyonov Good interviews usually don't ask about those details and if they do they will be happy with "I don't know, I have to look it up". And you don't want to work at places that have bad interviews, so no loss if that makes you fail the interview.
@nwp Back to the quote from the Standard. Forgive my lack of knowledge, but a variable is an lvalue, which is different from a "prvalue", correct?
Thus, does the quote apply to constants only?
nwp
nwp
12:59
I'm starting to really dislike value categories.
I dislike that the names for them are as non-descriptive as they can get
There used to be 4 IIRC. l, r, x, gl?
What is pr now?
there's actually prvalue, xvalue and lvalue
nwp
nwp
In theory I would now look up the value categories and check if that restricts anything, but I don't want to.
the rest are shorthands for describing "X or Y" (e.g. "rvalue" is shorthand for "prvalue or xvalue")
13:04
@milleniumbug For the actual discussion, I'd like to know if a variable is a "prvalue"? Because if ti's not, then the [conv] section os the Standard makes little sense to me.
nwp
nwp
Is that W that bjarne drew at some point still correct? Because that would mean there are 3/5 categories.
@nwp Then I'm lost. Does that mean we can't convert a variable such as float f =/*some expression*/ to an integer?
nwp
nwp
That means that for int i = f; the f is a prvalue because "it is an expression whose evaluation initializes an object"?
@iksemyonov I thought pr existed all along. But I, too, don't sweat the legalese
@nwp Ahh, gotcha! So the same variable can have different categories depending on the context.
Right, the taxonomy is for expressions, not for variables. Now that makes sense.
13:13
Jan 25 at 20:31, by milleniumbug
Since the terms "lvalue" and "rvalue" apply to expressions, you could say they are confusing and should be instead named "lexpression" or "rexpression"
Jan 25 at 20:32, by milleniumbug
But I'll say that naming is not the most confusing thing about C++, so I have no advice than to accept this and move on
Glad I've started this discussion. That's quite an important concept. Be right back.
13:39
hello can i ask a question ?
i expect it to be C++ since C isn't dynamic
lol it's even a resolved website
so my question is, is there a function somewhere in C++ that binds a variable to lambda funstion ?
sup? What am I doing wrong if I want a class to be derived from something but also want to maage the base as a member? I want to replace the base for example but it will look like a hack if class derives from it.
let's be said that v is a variable.
nwp
nwp
@Abra Lambdas have that built in. You don't need an extra function for that.
13:42
is there a way to bind v with some function f just when v is equal some constant ?
like bind(v,someconstant,f)
nwp
nwp
[v](){/*use v*/}
@nwp didn't get you!
@nwp so f is fired everytime v is changed ?
@Abra do you want a watchdog or what?
nwp
nwp
@Abra No. f is called every time you call it and it has access to v when it is.
@EuriPinhollow kindof
13:43
@Abra there is none in C++.
There are platform specific ways of doing it.
too bad, there is in C#
nwp
nwp
@EuriPinhollow That sounds super confusing.
And this is not "binding" in any way.
nwp
nwp
You can write your own class that does something on assignment, for example call a specific function.
@Abra if you mean INotifyPropertyChanged, then no, it's not really built in
it also involves a ton of boilerplate
13:45
@nwp yes it's because my wording, i don't find anything proprer to call it than "binding"
@nwp like a getter/setter ?
nwp
nwp
You can even template it so you can use On_change_caller<Type, Function>.
@nwp ok, how do I assign the base conveniently except static-casting this?
oh you mean properties
nwp
nwp
@Abra Basically like a setter that additionally calls the function. You can use the assignment operator instead of a proper member function to make it look pretty.
holy shit that took us a while to figure out
no, C++ doesn't have properties, but there's not much need for them
if you want to restrict the possible values that can be assigned to a data member, use a different type
13:48
@milleniumbug INotifyPropertyChanged in C#, that's it, is there equivalent in C++ ?
nwp
nwp
@EuriPinhollow You might be able to make the compiler perform an implicit conversion if the derived assignment operator is not viable. Why do you want to avoid the static_cast? It seems to solve your problem and looks appropriately hacky.
i thought of constructing a class that calls a function whenever the class is used but don't you think it's time expensive ?
since this is usually used in the context of GUI frameworks, you should be looking there
@nwp I want to know if there is a better way of doing it. Also you or MB already told me that some names are hidden from lookup even if derived class has no viable functions.
So if I want to assign to base I should write using Base::operator=. I'll do that instead of static cast.
13:53
@milleniumbug is there boilerplates in c++ ?
i thought it's just angularjs thing
@nwp it was you, I found the log.
In computer programming, boilerplate code or boilerplate refers to sections of code that have to be included in many places with little or no alteration. It is often used when referring to languages that are considered verbose, i.e. the programmer must write a lot of code to do minimal jobs. The need for boilerplate can be reduced through high-level mechanisms such as metaprogramming (which has the computer automatically write the needed boilerplate code or insert it at compile time), convention over configuration (which provides good default values, reducing the need to specify program details...
you'll be hard pressed to find a language which forces you to write no boilerplate whatsoever
nwp
nwp
@Abra I wish that was on one line. That would have made it very star-worthy.
@nwp jquery is much dynamic and morphic that i want all languages (including c) to be query based
it spares a lot a lot of pain tbh
nwp
nwp
Just use jquery and leave C alone. There is a lot of pain created by jquery that you wouldn't want to force on everyone.
13:58
@Abra this sentence doesn't make much sense
I dunno it's just a personal view. but i still think it would be clever to construct a library like <Cquery.h>
no it wouldn't
if you want that then you are programming in the wrong language
jQuery is for getting one or more elements in the DOM tree (and doing operations on them). how would you even map that to C
or, do you want DOM tree manipulation in C too
@milleniumbug there is no dom's in python too, but well , it's just a personal view nothing more.
same question applies: how would you map that to python
14:12
@milleniumbug there is a lib called pyquery, not for dom elements
but let's just skip this, my question is about bound variables
pyquery allows you to make jquery queries on xml documents
so... DOM
FTR
25 mins ago, by milleniumbug
@Abra no
25 mins ago, by milleniumbug
since this is usually used in the context of GUI frameworks, you should be looking there
nwp
nwp
I can't tell if you want to capture a variable or make a callback whenever a variable changes or something else.
a callback whenever a variable changes or something else.
this ^
nwp
nwp
Does "setter that calls the function" not meet your requirements?
i take everything that works lol
of course, if there is.
14:19
Where in the standard would I look up the point about "assigning an out-of-range value to an unsigned"? There is a mention of modulo division operation in the book, and that operation can be defined in two ways for negative numbers. I intend to find out if the definition of modulo division is defined in the standard.
@nwp so ... the only way is declaring a variable as class than defining a setter function for it right ,
nwp
nwp
33 mins ago, by nwp
@Abra Basically like a setter that additionally calls the function. You can use the assignment operator instead of a proper member function to make it look pretty.
yes, operator overloading is better.
thanks mate!
nwp
nwp
14:30
Note that you don't need any mArray or delete like in the example. You just need t = other; callback();.
If we assign an out-of-range value to an object of unsigned type, the result is
the remainder of the value modulo the number of values the target type can
hold. For example, an 8-bit unsigned char can hold values from 0 through
255, inclusive. If we assign a value outside this range, the compiler assigns the
remainder of that value modulo 256. Therefore, assigning –1 to an 8-bit
unsigned char gives that object the value 255.

This is the paragraph that I'm referring to. What I'm trying to understand is how signed ints are handled w.r.t. this paragraph.
(see full text)
nwp
nwp
Then the first quote applies.
So UB.
@iksemyonov yes, it happens to me much, this is why i prefer using long long integers
Can the book be wrong?
if i use int, big values get rounded
negative -> positive and so on
nwp
nwp
14:33
@iksemyonov Which part? The quote you showed looks consistent with the standard.
@nwp Then it's the second quote of yours, about modulo 2^n, for my quote from the book does not mention UB?
it's not UB unfortunately.
nwp
nwp
@iksemyonov Either you have signed then it's UB or you have unsigned then you get modulo. The quote only mentions the second case, but it's just a quote and the first case is probably mentioned elsewhere in the book.
@nwp "Therefore, assigning –1 to an 8-bit unsigned char gives that object the value 255" - this doesn't look like a UB statement, does it?
nwp
nwp
No why? -1 is out of range for unsigned char so you get modulo which makes it 255. Looks correct to me.
14:37
My main point w.r.t. signed numbers is that the representation is impl defined, isn't it? So the 255 is for two's complement, e.g..
nwp
nwp
Arithmetic modulo defines -1 % 256 to be 255, so the result is required to be 255 no matter what platform you are on.
Oh, that's the way it works. Gotcha. So no number is signed in the calculation, save for the very first one, that is out of range.
I got tricked by the fact that -1 == 255 in a sense, in a certain representation, if you see what I mean.
nwp
nwp
Well, the certain representation is %256-land. Not sure how that is a trick, that's what algebra defines and the C++ standard copies.
@nwp What I mistakenly thought was this: -1 means 8 bits set in a certain representation, as is 255. See?
is there a way to prevent it except calculating number of digits ? log2(value)
nwp
nwp
14:45
Apparently wikipedia doesn't know the proper name of %256-land. It only has french, german and japanese.
It's probably "residue ring", but no wiki entry for that.
@Abra You can use a bignum library that grows to fit any number. You can also use sanitizers to catch signed overflows if you only care about detection.
or there is gmp lib too
the case of gmp libraries, i guess that it uses long variables as classes or templates. then attach pieces togather in case of additions.
nwp
nwp
@Abra Which is a bignum library.
15:14
@nwp congruence class, residue class
https://en.wikipedia.org/wiki/Modular_arithmetic
section "Congruence classes"
nwp
nwp
Looks like wikipedia messed up the links a bit. The french version of that article seems to not mention that part and the german one is completely absent. Weird.
Regardless, we now know the right term.
@nwp "Arithmetic modulo defines -1 % 256 to be 255" - is that the information encoded in eel.is/c++draft/basic.fundamental#4 ?
Sorry if I'm being a bit.. boring about this, but I'd like to understand the passage form the book fully. You've already helped me a lot today. Now the remaining part for me is to firmly understand what exactly defines "%" to yield a positive remainder.
nwp
nwp
@iksemyonov Well, the standard doesn't directly say here that -1 % 256 = 255. You would need to look at a math book or wikipedia for that which I believe to be what "arithmetic modulo" is supposed to indicate.
@nwp But, anyway, that is the starting point on that matter in the Standard, correct?
nwp
nwp
I'm not sure what that means.
15:29
Hmm, let me rephrase..
nwp
nwp
The definition of arithmetic modulo would be for example here which forces the result to be >= 0.
Is the section of the Standard that I've linked above the exact point that defines the remainders to be positive? - that would be a better formulation of my question.
nwp
nwp
Indirectly yes. It defines unsigned assignment to have arithmetic modulo which you have to somehow know means positive.
OK, that's nice, I think I can stop here. One more related question though. Am I right that the behavior described in the passage that we're discussing is implemented in assembly, not in silicon?
I.e. it's a higher-level abstraction that builds on the lower-level CPU instructions.
nwp
nwp
The standard is basically implemented in an imaginary machine (called a virtual machine I think but that is confusing) and real implementations must behave like the imaginary machine. If that involves silicon or assembly or magic doesn't matter.
15:40
it may even include a human doing all the manual work
nwp
nwp
In practice I would expect CPUs to have assembler instructions with the proper semantics. Otherwise a compiler basically has to implement a function in assembly that does what the standard wants.
(which is what used to be done with pre-x87 floating point arithmetic)
but if the signed int is represented in 2's complement then signed->unsigned is free
user7390988
16:10
Hi everyone, I was trying to create a template function called getComponent() for a GameEngine I'm working on. I have a "Component" super class, and a bunch of subclasses like a "Transform" class, that holds position, rotation and scale. Inside the GameObject class I am trying to write a function called getComponent, using templates. I would like to write something like:
user7390988
GameObject go;  go.getComponent<Transform>();
user7390988
i tried using templates, like this:
user7390988
template<struct T>
	T getComponent <T>()
	{
		for (int i = 0; i < m_Components.size(); i++)
		{
			//if the component at index i has a the type X return an X component

		}
	}
user7390988
but it gives me lots of errors
yes because syntax is wrong
16:12
+1
fairly sure template<struct T> is not a thing
also don't write identifier<T>() unless you're writing a specialization (and you aren't)
it's just T getComponent()
user7390988
how should i create it then?
template<class T> or template<typename T> (same thing)
I'd say there is a fundamental misconception here. C++ isn't Java. Walking thorugh a lit of objects and asking for their type is not exactly idiomatic C++.
Referring to //if the component at index i has a the type X return an X component
well I didn't even want to get to that part
16:14
This looks like Prototype + Factory to me. Also, use a tree or a hash instead of a linear walk.
user7390988
Wouldn't it be easier to write a separate function of each component type?
The basic problem here is that C++ doesn't have heterogeneous containers. There is runtime dynamic polymorphism, on the other hand.
my approach for gesture tracking was to inaccurate so i changed to coliru.stacked-crooked.com/a/00d1ffded401691f ....the base class pointers to Gesture i will store in my gestureBuffer.
@FerencRozsa line 34 should be protected?
@iksemyonov no..i have to set/get it from outside
user7390988
16:26
thanks anyway for the help
@GabrieleVierti FTR, you're writing yet another ECS, if you look around github, you would be able to see a lot of them around
user7390988
16:54
@milleniumbug yeah, but the ones i saw were super complicated..
yes, this is what typically happens to these systems, when they collide with real life requirements
and if your total types of components and entities stays small you have no need for a complicated general solution
and can instead put in a few std::optional<MyFirstComponent> member fields in the entities
17:45
@all quick question regarding std::map<key, value> in c++. If the key does not exist, would below line create a new key and set its value to true?
MyMap[SomeKey] = true;
it would first create a key-value pair (SomeKey, default_value_for_that_type) and then assign true as the value
nwp
nwp
Basically yes. Assuming value can be assigned true.
Excellent !
thank you guys and hope you guys are doing well :)
@milleniumbug @nwp Love++
 
2 hours later…
20:02
Has anyone yet encountered a problem with setting up extensions in VS2017 ?
i'm talking about MSVS, not VSC
I am, too
it seems there is some issues with the latter version of VS
VSC follows different versioning scheme so there's no room for confusion
I'm running MSVS2017 with Resharper, VsVim, XAML styler, Code Maid and I see no problems
20:04
really ?
can't install the slightest !
i'm on raw VS, hate my life.
nwp
nwp
You said that already.
yea, i should be following the don't repeat yourself principle.
nwp
nwp
(I meant VS and hating your life. I should follow the don't be ambiguous and don't try to be funny principle)
ok then i apologize if i appeared silly, i just don't know how to fix the bug in VS, should i reset the whole software?
nwp
nwp
That's what you do on windows right? Reinstall VS, reinstall windows, buy a new computer. Repeat until problem is fixed.
20:15
try first repairing it from the "add/remove programs"
@nwp as a final recourse.
20:50
@nwp well it's a known bug already if none did step through it yet.
nwp
nwp
@Abra It says they fixed the bug. You are using the latest version, right?
@nwp 2017, not its update.
nwp
nwp
Well, install the update that fixed the bug.
21:47
hello, i saw this sample code that had this:
int __cdecl main(int argc, char **argv)
{
i search for what __cdecl was but i still dont get what it is
can someone explain what it does?
what is the diference between int main(...) and int __cdecl main(...)
nwp
nwp
It specifies the calling convention.
in this case what does it specifie to?
should i use that every time?
it say its forC/C++
what are examples i would use that over a normal int main ?
nwp
nwp
The reason you need that is when you want to link stuff together. Normally your compiler picks a calling convention and compiles everything with it so everything fits, so there is no need. But sometimes you have a .dll that uses a specific calling convention and your program has to call its function with the correct calling convention, otherwise bad things happen.
Generally the library's header takes care of it though. I have no idea why you would want to apply that to main.
21:52
ohhh ok i get it
i saw it in a sample code for a socket
here ^
nwp
nwp
The winapi documentation is intended for developers in general. They try to be very obvious and explicit, so they write for example char buffer[42] = {0}; even though the 0 is implicit and __cdecl main even though that is the default. The idea is that, say, delphi developers understand the code and know how to call a function, because for them it might not be obvious and explicit.
This leads to poor C code that has a C++ tag. Try not to learn anything from it.
ohh ok, thanks, ill keep that in mind!
22:07
Hi everyone. Is it good idea to install gcc 4.4.* on Ubuntu 16.04 LTS (manually, because it's unavailable in the official repository for this release)? Of course not instead of the default one, but as completely distinct binary? Would it be much of a hassle?
nwp
nwp
gcc 4.4 is ancient. You don't want that.
I want, because I need to use it at work, on testing/production environment.
nwp
nwp
15
Q: Installing gcc-7 (and newer packages) in Ubuntu 16.04

wsedrftgI am running Ubuntu 16.04 LTS and I want to install a newer version of GCC, specifically gcc-7 which released May 2, 2017. There is a package for it in the Toolchain test builds ppa, but the Ubuntu version listed next to it is 7-20170407-0ubuntu2 (I have no idea what this corresponds to). I tried...

What does ubuntu 16.04 come with by default?
And I know how to install gcc-7, I done that much time ago ;)
5.4.1
nwp
nwp
Ah, so you have a semi-modern gcc but you want to install an old gcc to test work stuff.
22:12
Yep.
nwp
nwp
Well, the way to install software on ubuntu seems to be to give random people on launchpad.net root access to your machine.
You did try apt-cache search gcc and see if they have a version you can use right?
Hmm, the oldest gcc that I saw on my work machine was gcc-4.7, but now, on my home machine I can see 4.4.
nwp
nwp
2
Q: How to install gcc-4.4 on Ubuntu 16.04

Hodjat Asghari EsfedenI'm gonna compile Rodinia benchmark on Gem5-gpu simulator, when I make it complains for gcc-4.4 and give me following error: make gem5-fusion make -f Makefile.gem5-fusion make[1]: Entering directory '/home/hodjat91/Desktop/gem5-gpu/benchmarks/rodinia/backprop' gcc-4.4 -DOUTPUT -O3 -I../../../gem...

It seems it's present in the toolchain test builds PPA.
Then it seems I don't have question anymore, too. Thanks :)
22:34
Good evening!
So I'm currently working with C, and trying to check if a string contains a substring.
I realise the strstr() exists, and while it works, it works a bit too well
My problem is, is that I'd need to check if a given string contains a WHOLE substring. Currently, the original string contains "1000". If I do the check to check if it contains "1000", it works, but it also works if i enter "100" - because "100" is also a substring of "1000"
This is what I am looking at right now
Any, and all help, is greatly appreciated!
nwp
nwp
convertedN looks like a memory leak
It is right now
But thats because it was literally just implemented
nwp
nwp
how about char *found = strstr(data, "100"); if (found) { if (isdigit(found[sizeof("100")]) continue; }?
I can try it, but how would it help getting the sizeof 100?
And sending it to the index part of the array?
nwp
nwp
The idea is to use regular strstr and then check if the character after the number is a digit. If it is then you have a case like "found 100 in 1000". Otherwise it's a real 100.
22:49
I see
Well, atleast what i tried didnt seem to work
And then I assumed "data" is the string of, well - data. And "continue" equals to it being a real 100
It doesnt seem to like it, but I''d really want to do something like this:
int temp = 0;
fscanf(file, "%d", &temp);

// In this case, n will be 100
if(temp == n) {
   continue;
}
Problem is, one line in the data file is "[string] [string] [double] [int]"
nwp
nwp
every line?
Well, yes. Every line follows the same template, but doesnt necessarely have the same content
@nwp your solution allows inputs like "000".
nwp
nwp
scanf("%s %s %lf %dn", first_string, second_string, &the_double, &the_int); didn't work out?
fscanf(file, "%s %s %d %lf", tempString1, tempString2, &tempInt, &tempDouble);
If anything, it'd be that
And that segfaults
nwp
nwp
23:05
Did you provide proper memory for the strings?
Alright
ahem
TIL that:

char *tempString1 = (char*)malloc(sizeof(char) * 10);
char *tempString2 = (char*)malloc(sizeof(char) * 10);

Does not equal

char *tempString1, *tempString2 = (char*)malloc(sizeof(char) * 10);
nwp
nwp
Not that it can be proper, but at least some memory. And arguably it should be "%100s" or whatever buffer length makes sense.
It doesnt fetch the digit yet which is a bit odd, but hey, it doesnt segfault
nwp
nwp
Does your file actually only have 9 or less characters?
fscanf returns the number of parameters correctly read. It probably doesn't equal 4 because it failed reading something.
What does the first line actually look like?
Not really, no. I just went with something for testing purposes, which in hindsight is just as stupid as some previous mistakes
Literally the first line?
Insertion Sort Random Array 1000 1.00 ms
So I got a very good guess on why it isnt working, but working on a fix now
If I print the result of fscanf, I get two all across the board. So you are correct
nwp
nwp
23:11
I think it takes "Insertion" as the first string, "Sort" as the second and then says "Random" is not a double.
Precisely my thoughts
A natural way of bypassing that would be fgets, me thinks.
But thats not entirely possible here, from what I can see?
nwp
nwp
Well, the format that you specified and the format that the file has don't match. You must make one like the other.
Mhm
Not a clean way, but when we insert the data into the file, put a underscore between the words that are supposed to be connected, and when we output it, filter them away?
Feels all sorts of dirty though
nwp
nwp
Alternatively use quotation marks or parenthesis, but that makes parsing more difficult.
Or that
Hold up
nwp
nwp
23:17
Or maybe instead of making up a format use json and a json library to do everything for you.
fscanf(file, "%s %s %s %s %d %lf", tempString1_1, tempString1_2, tempString2_1, tempString2_2, &tempInt, &tempDouble);
How bad's that?
bad, strings can have spaces this will screw you up
Thing is
nwp
nwp
You forgot the "ms".
Ah, that too, yeah
23:20
The trick is to not write code, just use cereal...
Thing is,
nwp
nwp
Yeah, except that's in C, so no cereal.
[string string] [string string] [double] [int] ms
That will always be the format, though
nwp
nwp
Well, if you're wrong then stuff breaks :P
23:21
Is this some bullshit school project?
Perhaps
But I like to not refer to it as such, make it more of a learning experience than put all the focus on the fact that its a school task
You should learn to prefer C++ over C... But, yes, I can understand that there are certain things in life not in our control.
We just started with C++. But this task and all previous ones have forced us to use C.
Were I to decide, i'd happily do this in C#
Compared to C, that is
But judging from the cast to malloc you're probably using a C++ compiler :-/
GCC
Through windows powershell and mingw
nwp
nwp
23:27
so... why are you casting malloc?
Habit, mostly
Because I did run it through G++ earlier
nwp
nwp
Bad habit. Get rid of it.
I know, i know. The more casts a code has, the worse it is, generally speaking
use new ?
I know, i know. The more casts a code has, the worse it is, generally speaking
nwp
nwp
23:28
@Abra Not in C. Also a terrible idea in C++.
I'v heard about discarded use of type casting for malloc in C.
so in C++ it applies also.
nwp
nwp
@Abra What?
(type*)malloc(thing)
nwp
nwp
You never do that. It's pointless in C and even worse in C++.
reinterpret_cast, but some kind of cast is required in C++
23:39
Anyways, i guess i should try to get some sleep. Not tired at all, but I do have to be up in about 6 hours
But cya'll around!

« first day (581 days earlier)      last day (2496 days later) »