Anonymous
https://pastebin.com/uSZNZTa6
Anonymous
so i have three documents, a makefile, a main.c file, and a csv file with some data. if you look at the make file its suppose to reroute the input for scanf from the keyboard to the csv file, so the data input is coming from the csv file, and the output is suppose to be a json file, the thing is the output file does not output properly
Anonymous
its seems to not be getting the data from the csv file
Anonymous
the csv file has 4 elements of data per student, an id number, first, lastname, and age
Anonymous
separated by ‘:’
Anonymous
same as i did in the scanf in the main.c file
Anonymous
the make file , just makes an object file, compiles the object file, executes , and opens the json file that is suppose to the output
Anonymous
the issue seems to be the input
Amir
I have read the rules and I'll follow
Anonymous
nvm guys
Anonymous
figured it out scanf("%i:%19[^:]:%19[^:]:%i",&id,firstName,lastName,&age);
Anonymous
i had to change the format specifier for the string
Anonymous
[^:] basically mean keep feeding me characters until i see : then end
Pete
Quick sort algorithms using partition:
Pete
I have to get the first element, a randomized element, and the median. I’ve done 2 but I wanna run through the logic of the median one.
Pete
So I have 3 numbers, first element in array, last, and middle. Can I just compare those numbers, get the mid and use that as my median?
Anonymous
Pete when did you start algorithms
Anonymous
how long after you starting learning c/c++
Pete
Maybe 1 1/2 years
Augmented
; can be used on the same row as many times as you wish
yes, i know, but some code beautifiers split these ";" on separate rows, on contrary they join multiple rows if ending with "," in a single row, until it ends as usual with ";"
Augmented
prefer ;, since , makes lines long and nasty
yes, but sometimes, if you expressions are short, or related isn't it better ? void yellow() { r = 100, g = 100, b = 0; }
Artöm
If this rgb stuff is repetitive, I'd make another function to set things up
Artöm
And I always break after {
Artöm
Just preference
Artöm
And I always break after {
Even in one-line if, yep
Augmented
No
i just gave short simple example... with "," you can list few operations without { }, after while, for, etc
Artöm
I'd like to see it splitted to 5 lines
Artöm
I instantly think why while was used and not for
Augmented
Artöm
Yhis usage is a sign that code block is not that simple and you need {} at least
Augmented
Artöm
This hurts readability without positive perfomance income
Artöm
Assembly is same I suppose
Augmented
okay
Augmented
is it better now?
バレンタインがいない柴(食用不可)
Augmented
This hurts readability without positive perfomance income
is it more readable with "for" constuction like that
Augmented
or it is better this way
Augmented
Artöm
for (size_t i = 0; i < size * sizeof(Type); ++i) { update(pBytes[i]); }
Artöm
Nice and clear
Augmented
for (size_t i = 0; i < size * sizeof(Type); ++i) { update(pBytes[i]); }
i affraid that compiler might recalculate size*sizeof(Type) multiple times, when evaluating for condition
Artöm
No sane one would
Artöm
If it bothers you, do size_t iters_amt = i < size * sizeof(Type);
Augmented
No sane one would
some processors have indexing registers, some have pre and post increment and decrement addressation
Artöm
Same I guess. Both are self explanatory and understandable
Augmented
Same I guess. Both are self explanatory and understandable
I mean like performance, incrementing with 1 should be faster, than adding base with index
Augmented
I mean like performance, incrementing with 1 should be faster, than adding base with index
if I use indexing [], then typecast can be inlined, instead of having const pointer
Augmented
Augmented
however, this approach with [i] compiles 30 bytes longer, than incrementing the dereferenced pointer as parameter for update()
Artöm
This code is just wrong
Artöm
Cast needs to be performed before indexing
Artöm
Also same for a structure https://godbolt.org/z/XAY9g7
Augmented
Cast needs to be performed before indexing
yes, my bad, indeed it was wrong...
Augmented
yes, my bad, indeed it was wrong...
your suggestion is quite nice, thank you... it's strange that having ++bytes in "for" is 8 bytes longer, compared to update(*bytes++);
Augmented
your suggestion is quite nice, thank you... it's strange that having ++bytes in "for" is 8 bytes longer, compared to update(*bytes++);
it's also resolves my fear that some stupid compiler can multiply multiple times while evaluating the "for" condition, counting down to 0 is quite smart too, thank you again
Augmented
This code is just wrong
Sorry, I replyed to myself few times, i mean THANK YOU, here is my full unit, https://godbolt.org/z/DCfb2F any other suggestions, which can lead to better readability and portability aswell?
Abdullateef
Ok
Augmented
Augmented
is this better, or not?
Augmented
hello everybody, is ternary operator, more readable, than if/else ?
Francisco
This one is definetely clearer
Augmented
This one is definetely clearer
okay, but it's so simpler with the ternary operator, and the comment above clarifies everything? is it allowed to use such constructions, when its not something complicated, and the comment above is explainatory... or we should keep things selfexplainatory but longer...
Francisco
is this better, or not?
Here, we might think _instance is a bool, therefore hiding important information. The comparison with NULL makes it a hundred times clearer (although nullptr should be used). Also, complex constructs via ternary operator are probably not what you want
Francisco
I would reject the second snippet and enforce the use of nullptr in the first one
Augmented
I would reject the second snippet and enforce the use of nullptr in the first one
okay, thank you so much, NULL is a macro for nullptr, i made for a specific platform port, i will switch to the built-in nullptr
Francisco
okay, thank you so much, NULL is a macro for nullptr, i made for a specific platform port, i will switch to the built-in nullptr
nullptr is not built in, but rather a variable of type nullptr_t, that's way safier than NULL
Augmented
Francisco
An if is still way more readable. And you really don't gain anything with the ternary
Augmented
Augmented
An if is still way more readable. And you really don't gain anything with the ternary
yes, i understand, but somehow i am tempted by the single line expression 🙂
Francisco
yes, i understand, but somehow i am tempted by the single line expression 🙂
A one-liner is not always that readable. We're not in Python
Augmented
A one-liner is not always that readable. We're not in Python
I came from assembly, Python I still avoid like hell... I like C, now i am mostly going for a full C++, but still learning and asking people silly questions... Thanks to all of you guys for the help