Anonymous
Hey need help with this .
Anonymous
the cherno on youtube had a good video on benchmarking as well. Some people use the windows api for benchmarking as well. Just be aware especially when using a debugger and breakpoints, that there is a great difference between execution time and time passed on the system clock.
Anonymous
Program Number 3: Date Printer Write a program that reads a char array from the user containing a date in the form mm/dd/yyyy. It should print the date in the form March 12, 2014.
For example
Enter Date 5/14/2019
May 14, 2019
Validation Required: Month should be less than 13, day should be less than 31.
Anonymous
Uhhm honestly, that is just a matter of using a switch statements and do some sane checks on the entered values and bringing them into the right format.
Anonymous
look up how a switch statement works and that should already give you half your answer to that program
Anonymous
how do I get mm and dd and year separated?
Anonymous
Ah i see. there are mutiple ways of doing it. The C way of doing it would be to iterate over the characters until you hit a / or null and parse the format that way. The C++ way of doing ist would be to tokenize the string with / as a seperator.
Anonymous
there is either a function or a method of std::string for that. Im not quite sure anymore, but im certain you can look that up pretty esily
Bottom G
Hi, where is pinned message ?
Bottom G
## Rules #pinned
* You are not entitled to an answer, getting angry about not answered questions will get you warned.
* Not checking your problem in google (or any other search engine) first will get you a warn.
* Asking to solve an assignment/test/whatever without trying it first yourself will get you a warn or will get you BANNED. We won’t write a code for you, but we can push you forward and suggest something.
* Before posting a long code snippet think twice and read the Resources section below.
* No “best book” or “best youtube channel” requests, use /get cbook and /get cppbookguide chat commands.
* No “best ide” requests, use /get ide chat command to see the suggestions.
* Asking for something that is in the pinned message right after joining WILL GET YOU BANNED.
* C/C++ discussion preffered (assembly also allowed), asking about other languages (or groups for other languages) right after joining will get you BANNED.
* Reverse enginnering, hacking and related topics are allowed, but asking to hack facebook, instagram, etc. is NOT allowed. Also if you ask "how to become a hacker" and obviously have zero knowledge on anything related to that you may get warned or banned.
* Legitimate requests for help on code and programming questions are welcome. A request is considered legitimate if it describes your problem, what you've done so far and what went wrong. Requests such as "write my program" or "do my homework" are never considered legitimate. Asking not legitimate questions will result in a warn or ban. See https://stackoverflow.com/help/mcve on how to write good questions.
* Asking for book recommendations is ok, but "pls give pdf book" is not allowed, find books by yourself. Posting illegally copied books (or links to those books) is also not allowed and will get you BANNED.
* Only English language is allowed, if you speak shitty English or don't understand anything in English YOU WILL BE BANNED.
* A little bit of programming related memes, jokes, shitposting are allowed.
* NSFW content (porn, nudity, etc.) is not allowed.
* Spamming/advertising (job posts are also ads, so ask an admin before posting) will grant you a warning or an immediate ban if you do it right after joining.
* Religion, politics and ideological topics are forbidden.
* Long code snippets must be posted via a snippet website(links below), posting pictures of code and posting long snippets in the group is not allowed.
* If you encounter a problem, while using dev C++ or turbo C/C++, you will not be helped, use another more modern IDE.
* Don't post compiled executables, that is obviously a security risk.
* Personal messages without asking beforehand are not allowed.
* If you want to post a link or some article in this chat you will need an admin approval first
## Resources
C/C++ group India: http://t.me/c_cpp_india
About asking good questions:
* [English](http://www.catb.org/esr/faqs/smart-questions.html)
* [Translations](http://www.catb.org/esr/faqs/smart-questions.html#translations)
For posting long code snippets:
* [GitHub Gist](https://gist.github.com)
* [Ubuntu Paste](https://paste.ubuntu.com/)
* [Pastebin](https://pastebin.com)
## Reports
If you notice any forbidden content, please use the /report command while responding to the offending post to report it to the admins.
ok
Jasur Fozilov 🐳
Which site do you recommend learning full c ++ ?
Chinaka
Anonymous
g3rm4n
Hey, i need to allocate dynamically a new string with size from count value.. for example the count is 4, strlen of string 3 need to be 5 (4 + 1 for '\0')... but i get strlen 11
Anonymous
Chinaka
has been a hook on my neck for over a week now
Chinaka
please i need help and assistance
g3rm4n
char* String3 = NULL;
String3 = (char*)malloc(((Count) + 1)*sizeof(char));
Anonymous
Bottom G
Chinaka
which distro?
am a newbie to coding so i dont knw wt u mean by distro
Anonymous
What linux operating system do you use? Like a debian? Ubuntu? Arch?
Bottom G
/get cbook
Anonymous
am a newbie to coding so i dont knw wt u mean by distro
assuming you are running a debian based distribution. I think the package manager there ist apt, right?
open a termal and enter: sudo apt-get update; apt-get install vscode
At least i assume that is the package name.
Chinaka
Chinaka
this is so frustrating😫😫😩😫😩
Chinaka
should i just go and use windows
Logan
ya you should if you dont have use with the linux
Logan
os
MᏫᎻᎯᎷᎷᎬᎠ
Anonymous
should i just go and use windows
Honestly linux dostos are usually more user friendly for new computer users i think. Bit i have heard other opinions on that as well. What problem do you face exactly?
Chinaka
Anonymous
Sure, but i gtg soon
Anonymous
The easiest way to start learning, from scratch, is usually to take a class. If that isn't an option things may be more or less uphill... Or not, but it can definitely be uphill bumping into every possible hangup.
Anonymous
C++ has a really big and helpful community tho.
Anonymous
For example beeing in chernos discord or one lone coder is another cool one. It's almost as if you had a class with students to ask things you didnt understand at first.
Nomid Íkorni-Sciurus
Anonymous
Normally, in a class there would be a computer lab and essential softwares pre-installed by lab technicians. Some training companies expect you to buy a new laptop to take their courses...
Diego
Hey guys
I wanted to know if you'd think it's a good idea to specifically instantiate an object at the end of the heap (like, endofheap address - sizeof(myobject))
I specifically thought about doing this because I want to create a temporary collection that cannot live on the stack since it'll exist across multiple calls, but once all the adds are made, and all the processes done, it'll get deleted
I'm working on an embedded system with only 8MB of RAM and I'm trying VERY hard to prevent memory fragmentation as much as possible
It's also worth mentioning that memory management is implemented with the heap being all of the space in between static memory, which is at the start of RAM, and the stack, which is at the end of it
Diego
I also expect new objects to be allocated after I create this "collection"
Hence the source of my problem
ken
Anonymous
İntegral DX🔺️
Hello. I'm trying to write a program that calculates the instillation of nose type integrable functions. But what I want to do Sample: 1) Press to add a trgonometric expression. 2) Polynomial term Press to add. I do not want to do it. In addition, the user will type commands from the keyboard and this program will immediately recognize the matte functions used immediately. How can I do that?
Andrew
Andrew
are you writing a simple console program?
Anonymous
If allowed to choose the input language, a RPN string of tokens (like in FORTH) could be adequate, ugly but adequate...
İntegral DX🔺️
BB 24 🔵
Hlo
klimi
Hlo
Don't say just Hlo
Anonymous
https://codegolf.stackexchange.com/questions/175485/the-first-the-last-and-everything-between
void between(int a, int b) {
int inc = (a <= b) ? +1 : -1;
printf("[%d, %d", a, b);
for(int i = a+inc; i != b; i += inc) printf(", %d", i);
printf("]\n");
}
Anonymous
Darnit, that's wrong on 4, 4.
Programmer
https://codegolf.stackexchange.com/questions/175485/the-first-the-last-and-everything-between
void between(int a, int b) {
int inc = (a <= b) ? +1 : -1;
printf("[%d, %d", a, b);
for(int i = a+inc; i != b; i += inc) printf(", %d", i);
printf("]\n");
}
How about this one:
void between(int a, int b)
{
int inc = (a < b) ? +1 : -1;
printf("[%d, %d", a, b);
for (b -= inc; inc * a < inc * b; printf(", %d", a += inc));
printf("]\n");
}
Diego
Hey guys
I wanted to know if you'd think it's a good idea to specifically instantiate an object at the end of the heap (like, endofheap address - sizeof(myobject))
I specifically thought about doing this because I want to create a temporary collection that cannot live on the stack since it'll exist across multiple calls, but once all the adds are made, and all the processes done, it'll get deleted
I'm working on an embedded system with only 8MB of RAM and I'm trying VERY hard to prevent memory fragmentation as much as possible
It's also worth mentioning that memory management is implemented with the heap being all of the space in between static memory, which is at the start of RAM, and the stack, which is at the end of it
Well, in my specific case I reasoned I could just do all the tasks in a separate function, and therefore create the collection on the stack and pass its address; and when it gets back to main() it'd already be deleted, but all the processing will have been made
olli
Hey guys
I wanted to know if you'd think it's a good idea to specifically instantiate an object at the end of the heap (like, endofheap address - sizeof(myobject))
I specifically thought about doing this because I want to create a temporary collection that cannot live on the stack since it'll exist across multiple calls, but once all the adds are made, and all the processes done, it'll get deleted
I'm working on an embedded system with only 8MB of RAM and I'm trying VERY hard to prevent memory fragmentation as much as possible
It's also worth mentioning that memory management is implemented with the heap being all of the space in between static memory, which is at the start of RAM, and the stack, which is at the end of it
If you don't know the size of the collection ahead of time, you either need to do as you planned or use some sort of allocator. A memory pool with different sizes keeps fragmentation low, however you might waste memory for padding purpose. When "growing" - how do you deal with allocation failures? (which might happen).
If you can estimate an upper bound of elements, you could allocate the collection statically ahead of time or on the stack when needed. In the second approach you still might run out of space (and stack corruptions might be hard to detect).
If you use global memory / shared memory, remember your functions modifying the collection are not reentrant / thread-safe.
What do you store in these collections? Can you change your algorithm to work on a "stream" so you don't need to add all the objects?
Diego
If you don't know the size of the collection ahead of time, you either need to do as you planned or use some sort of allocator. A memory pool with different sizes keeps fragmentation low, however you might waste memory for padding purpose. When "growing" - how do you deal with allocation failures? (which might happen).
If you can estimate an upper bound of elements, you could allocate the collection statically ahead of time or on the stack when needed. In the second approach you still might run out of space (and stack corruptions might be hard to detect).
If you use global memory / shared memory, remember your functions modifying the collection are not reentrant / thread-safe.
What do you store in these collections? Can you change your algorithm to work on a "stream" so you don't need to add all the objects?
In this collection I store references to all of the objects I want to call a specific method from
I have different classes implementing a base class for different dedicated tasks in my system, and each of them have a "Start" method
In the loop where I initialize ALL of my tasks, I send this collection over to them so that they can add themselves on it, and this method is GUARANTEED to only be called once per object, and guaranteed to only be called before the main loop, so after all this is done, this collection is thus deleted
Then, all objects that added their references to it will be started automatically
Think of Window's "startup apps" folder, I don't want to keep a separate list that I need to maintain additionally, I'd much rather encapsulate this within the class itself
Diego
I usually achieve this in languages like C# using attributes, but perhaps that sort of bias is leading me to make poor design choices
Diego
It's also worth mentioning that in the future I may or may not add other methods that require similar functionality
Diego
If it helps, I'm working on a LilyGo TTGO Watch
It's basically an ESP32 with a touchscreen and other peripherals, as far as hardware is concerned
16MB Flash, 8MB RAM, programming it using Arduino; though I replaced setup and loop with my own main, of course calling init() before anything else
Anonymous
Anonymous
Arduino yun?
Diego
Arduino IDE and Arduino C has support for ESP32! :D
Diego
Thus any libraries compatible with Arduino are compatible with the ESP32
Anonymous
Anonymous
Anonymous
An alternative may be to allocate a large pool and hope the allocator recycles it well after free lol. Of course all the initiated classes would sit mid-way in memory...
Anonymous
If the classes contain elements that themselves require allocations then... :/
Is there anyway to profile memory usage? Either on metal or simulated?
aadityaninaniya
Can anyone send me the syntax of SECANT METHOD FOR FIND A QUADRATIC EQUATIONS ROOTS in c++
Diego
Buuut as I am now, regrettably, am still waiting for the actual package to get here 😓
Diego
Diego
Also this collection is a wrapper I made myself, where add merely sets the value in an array and moves an index up a space
Diego
I specify the size and have the objects freely add themselves without worrying about array size or their index
olli