|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
To feanorian,
I saw your question in the IRC some days ago but wasn't online when you sent it.
What you want is: char * const * c_string_pointer
Why? My technique for reading declarations in C is the "backwards" rule. I read from right to left, where each type-qualifier,volatile or const modifies the type immediately after it if its a pointer, or before it if its a type. Watch: char * const * c_string_pointer C_string_pointer is a pointer to a constant pointer of type char
With arrays and functions, you use the clockwise inside-to-outside rule, it can get very confusing for difficult, long functions or array types.
volatile foo * const * bar[len];
bar is an array of length len of pointers to constant pointers to a volatile foo.
int * volatile bar(char * const foo[])
bar is a volatile pointer to function with one argument, foo, which is an array of constant pointers to char, which returns an int.
|
On November 05 2013 04:02 obesechicken13 wrote:I'm having some problems with a website. Sitegrounds says we are going over the CPU load available for our site. We upgraded and are still going over and sitegrounds is shutting us down. It's definitely a cron issue rather than a visitors issue. All of the problems occur at 1AM or 2AM. HTTP CPU load is low but Cron CPU usage is high. ![[image loading]](http://i.imgur.com/EVimuE6.png) These cron job times are wrong. Add one hour for each one. Eg if it says it runs at 4:30, it really runs at 5:30 my time. Timezones. ![[image loading]](http://i.imgur.com/5nxRzRi.png) How do I debug this? I've looked at the error logs file and there's nothing from this month in it. Which files should I be looking at? Run each cron job one at a time and look at cpu usage?
ps -p <PID> -o %cpu,%mem,cmd
Not the most elegant way, but you don't have that many cronjobs
|
On November 05 2013 06:34 CorsairHero wrote:Show nested quote +On November 05 2013 04:02 obesechicken13 wrote:I'm having some problems with a website. Sitegrounds says we are going over the CPU load available for our site. We upgraded and are still going over and sitegrounds is shutting us down. It's definitely a cron issue rather than a visitors issue. All of the problems occur at 1AM or 2AM. HTTP CPU load is low but Cron CPU usage is high. ![[image loading]](http://i.imgur.com/EVimuE6.png) These cron job times are wrong. Add one hour for each one. Eg if it says it runs at 4:30, it really runs at 5:30 my time. Timezones. ![[image loading]](http://i.imgur.com/5nxRzRi.png) How do I debug this? I've looked at the error logs file and there's nothing from this month in it. Which files should I be looking at? Run each cron job one at a time and look at cpu usage? ps -p <PID> -o %cpu,%mem,cmd Not the most elegant way, but you don't have that many cronjobs Thought about that but then I noticed I couldn't run ps -p since I'm on a shared server.
I eventually realized there was something wrong with the sitegrounds reporting. Thank you to everyone who took the time to read what I wrote.
Sitegrounds defines CPU time as number of seconds used by a machine in any given hour. By that graph, I used 4.5million seconds of CPU in that one hour. Can't blame them, I'd cancel someone's account too if they were somehow breaking the time continuum to get more internet from me.
Tip('CPU time or CPU usage is the amount of time (in seconds)<br> a computer program uses in processing CPU instructions.<br> No Customer is allowed to use more than 20000 CPU Seconds<br> for any given calendar day. No Customer is allowed to use more<br> than 2000 CPU Seconds for any given hour of the day.<br><br><b>The hourly and daily statistics are being updated<br>each hour')
|
The red book definitely, you won't find anything as comprehensive online. Also its really big, but you don't have to read it from front to back if you know what it is you need to learn.
|
I have a question. C++.
So I want to have a file with various sections, and under each section, there will be sample names separated by commas.
So what I want to happen is that when a character in my game is born, it will open the file and jump to the relevant section and randomly select a name and apply that to the character object.
How do I do this? I only know the basics of ifstream/ofstream.
I want it to be dynamic so if I manually add names to the sections, the program will still be able to determine by itself how many there are in the section, and then to randomly pick one.
|
|
|
On November 05 2013 18:44 Nesserev wrote: Well, it all depends on how you format your file...
For example, if you format your sections like these SECTIONNAME name1, name2, name3, etc.
You can use the readline function in a while loop to find the appropriate sectionname, and then use a readline function again to put all the names in a string, and then use a function to process that string into an array/vector of strings...
There are so many ways to do it...
What I had in mind was something like this
********** ** Human Male region1 ********** name1, name2, name3 (...)
(others...)
********** ** Orc Female region2 ********** name1, name2, name3, name4 (...)
(etc)
|
|
|
Load the whole thing into memory once and keep it there. It's highly unlikely that this file would be so large that memory is an issue.
Ideally you would just use XML, no point in implementing a parser for your own format. You'd have to find a simple C++ xml parser. Something like this:
<section race="human" gender="male" region="TL"> <name>Reggie</name> <name>Gigas</name> (more names) </section> (more sections)
|
On November 05 2013 19:25 Reggiegigas wrote:Show nested quote +On November 05 2013 18:44 Nesserev wrote: Well, it all depends on how you format your file...
For example, if you format your sections like these SECTIONNAME name1, name2, name3, etc.
You can use the readline function in a while loop to find the appropriate sectionname, and then use a readline function again to put all the names in a string, and then use a function to process that string into an array/vector of strings...
There are so many ways to do it... What I had in mind was something like this Show nested quote + ********** ** Human Male region1 ********** name1, name2, name3 (...)
(others...)
********** ** Orc Female region2 ********** name1, name2, name3, name4 (...)
(etc)
http://www.cplusplus.com/reference/map/map/ http://en.wikipedia.org/wiki/Associative_containers_(C )
Just use a mapping and dump it to file. Best way to store data like that. Not only is it human-readable but also usable by the code.
Example:
typedef map < string, list<string> > map_type;
map_type name_map; list<string> h_m_name_list;
h_m_name_list.pushback("Joe"); h_m_name_list.pushback("Bill);
name_map["h_male_names"] = h_m_name_list;
You could do it with lists, arrays of strings etc. If you dump it to the file it'll look more or less like that:
h_male_names : ({ "Joe", "Bill" })
You can even nest maps inside of maps if you want (at least you can in other languages, been a while since I did something in C++).
|
I agree, keep a copy of the data in memory. Once you need to actually save this memory to a file you can dump it all in one go.
|
I need like a starter package on C. (that is just c, not c++ or c#)
Compiler, do I something like JVM to execute c programs, a resource to learn the commands etc. I would be ever so grateful if someone could point me in the right direction.
For some reason the editors vim and emacs were recommended to me. Haven't really used either yet, but I don't exactly see the point?
|
On November 06 2013 09:41 Mataza wrote: I need like a starter package on C. (that is just c, not c++ or c#)
Compiler, do I something like JVM to execute c programs, a resource to learn the commands etc. I would be ever so grateful if someone could point me in the right direction.
For some reason the editors vim and emacs were recommended to me. Haven't really used either yet, but I don't exactly see the point?
C is a minimal language. No need for a virtual machine like the JVM to execute your code in, as it will run directly within your host OS.
For compilers, I recommend using GCC. There are other compilers out there, but GCC is historically the most used. You can find it in the Mingwe (personally preferred) or Cygwin packages for Windows, or if using Linux, it's included by default in 99% of the distros out there.
People recommend vim or emacs as once you've learned them, they are easily the most efficient way to navigate code (arguably for any language). They each were originally built for Linux, but there are ports now for other general purpose operating systems as well such as Windows. I'd guess that what you really want is a familiar development environment to learn an introduction to C. For that, here's a link to my old alma mater's instructions for getting C set up for eclipse on Windows. http://www.rose-hulman.edu/class/csse/resources/Eclipse/eclipse-c-configuration.htm
|
On November 06 2013 09:41 Mataza wrote: I need like a starter package on C. (that is just c, not c++ or c#)
Compiler, do I something like JVM to execute c programs, a resource to learn the commands etc. I would be ever so grateful if someone could point me in the right direction.
For some reason the editors vim and emacs were recommended to me. Haven't really used either yet, but I don't exactly see the point?
Also, as far as editors go, you'll find that having a code browser of some sort with syntax highlighting and all of the other nice things that come with a full IDE is like... REALLY nice for working in C. Sure you can write all your programs in Notepad and compile them with the command line if you feel like... but being able to see typos and things that are just not legal before you even try to compile them is life-saving, and the debugging abilities that IDEs provide you with are also really hard to even imagine working without on anything more than two or three files large.
|
A lot of people that I've talked to say that IDEs are a bad way to learn a language for just that very reason.
|
Right tools for the right job... If you're handling just one .c file and one .h file, a full on IDE is going to confuse you more than help. Notepad++ does code highlighting and a single command in your terminal can run the program without having to learn how to create a new project, manage a makefile, add dependencies, etc... For writing C, I do so in an editor that is pretty close to notepad.
That being said, a good debugger is worth learning, and using gdb on the command-line is not ideal.
If you think about it, most of your time writing code is spent navigating the code, reading what it does. Nothing has more information about the code than a debugger during run-time. Static analysis will only take you so far in a weakly typed language like C.
|
|
|
United States15536 Posts
Question for the wizards in here: does anyone have any recommendations for a JavaScript library/framework for games development? I'm interested in doing game creation in HTML5 and there are a LOT of options out there, so I'm looking for some opinions.
|
On November 06 2013 12:46 Zorkmid wrote: A lot of people that I've talked to say that IDEs are a bad way to learn a language for just that very reason.
And this is why we don't post without fully reading what we're responding to. 0o
don't listen to me, I was responding mostly to the 'why should I use an editor' rather than the 'what tools should I get to learn c' =/
|
On November 07 2013 04:17 Cyx. wrote:Show nested quote +On November 06 2013 12:46 Zorkmid wrote: A lot of people that I've talked to say that IDEs are a bad way to learn a language for just that very reason. And this is why we don't post without fully reading what we're responding to. 0o don't listen to me, I was responding mostly to the 'why should I use an editor' rather than the 'what tools should I get to learn c' =/
I wasn't really responding to anything you said, just giving one point of view on IDEs as a learning tool. No need for the saltyness.
|
|
|
|
|
|