|
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. |
On March 07 2013 19:02 KainiT wrote:Hey guys, I have a question I will have have to do a c++ project for university(most likely some b+ tree implementation) which needs to be able to run on Linux The problem is that I have Windows 7 as my main OS and I don't really want to code using a virtual os, cause the whole thing seems kinda slow, So would it be a problem to code and test, etc in Windows(probably with Eclipse) and then compile it a final time on Linux after making some hopefully small adjustements? Or would I encounter a massive amount of errors, that are hard to remove? thx for your advice  Back in school I felt like I ran into a lot of errors when writing in codeblocks on Win7 and then compiling later on a linux machine. (I still am in school, just taking a year off).
I use cygwin a lot now because I don't like the windows command line, but I don't think anything would beat dual booting or having a dedicated linux machine. I dual boot my win7 machine with linux too. If you do have a dedicated machine, then synergy will make life much easier.
If your code needs to run on the linux machines at your school then you might want to code there in person, or use putty to remote in, upload your files (with svn preferably), and run it.
|
Pootie too good!4331 Posts
On March 07 2013 21:46 Ilintar wrote:Show nested quote +On March 07 2013 03:37 JonGalt wrote: Hey guys, so I am making a website and I want to incorporate a user login system. I am using phpmyadmin, lubuntu 12.10, html 4, and mysql. The problem I am having is that whenever I try to register a user, my browser just downloads register.php instead of adding the user to the database.
I think it has something to do with my apache2 conf files, but I haven't nailed it down.
I edited etc/apache2/mods-available/php5.conf and I created a .htaccess file in the same directory as my index.html where all it has in it is: Type application/x-httpd-php5 .php .phtml
Point is, I am totally lost and would love some insight! I am new to website programming. You almost answered the question yourself. You have to copy or link php5.conf from mods-available to mods-enabled.
How do I go about doing that?
|
Hyrule19174 Posts
sudo a2enmod php5
should do it
|
I'm parsing some cookies I made in javascript. I'm swedish so I thought I was clever using å ä ö to separate stuff in my cookies. It worked fine as long as I pasted my javascript in the addressbar, but now my code is too long to paste.
I tried using a jsquery (I run it from a site that already loaded it I think) to get the code, but then I run into problems with my å ä ö.
I need some help in either a) load the code using only javascript (best option) ; or b) getting my code to work with the jsquery loader.
Really appreciate some help guys!
edit: include-javascript-file-inside-javascript-file I don't know if this is what I want? Really confused by now '
edit2: Found out you can define the charset of the code your importing. Setting it to ISO did the trick!
|
|
|
Pootie too good!4331 Posts
On March 08 2013 01:14 tofucake wrote: sudo a2enmod php5
should do it
Whelp. It was already enabled. Back to the drawing board I suppose. Super annoying. I don't really know enough about apache, php, mysql, and linux to really understand. I am kinda flyin by the seat of my pants/learning on the fly.
|
On March 07 2013 19:30 JonGalt wrote:Show nested quote +On March 07 2013 19:02 KainiT wrote:Hey guys, I have a question I will have have to do a c++ project for university(most likely some b+ tree implementation) which needs to be able to run on Linux The problem is that I have Windows 7 as my main OS and I don't really want to code using a virtual os, cause the whole thing seems kinda slow, So would it be a problem to code and test, etc in Windows(probably with Eclipse) and then compile it a final time on Linux after making some hopefully small adjustements? Or would I encounter a massive amount of errors, that are hard to remove? thx for your advice  I had the same issues in university as well. I always coded in Windows using notepad++ from home. However, I would save all my work on university account using a mapped network drive and a vpn. Then using putty, I could connect to my university's linux computers where my work was saved and run it thought the putty terminal. Win win!
That's pretty much what I also did until now, but as this project will be a little more complicated I would like to use the debugger, etc of Eclipse
misirlou wrote If you are using eclipse or other IDE that isn't Visual Studio you will be mostly fine. The only thing you need is compile the code on a Linux Machine after you wrote it and tested it on Windows. However, some libs and commands are Windows or Linux only and you will have to be careful with those. Thx for the advice, as I don't use Visual Studio and barely any libs I guess this won't be a problem.
obesechicken13 wrote Back in school I felt like I ran into a lot of errors when writing in codeblocks on Win7 and then compiling later on a linux machine. (I still am in school, just taking a year off).
I use cygwin a lot now because I don't like the windows command line, but I don't think anything would beat dual booting or having a dedicated linux machine. I dual boot my win7 machine with linux too. If you do have a dedicated machine, then synergy will make life much easier.
If your code needs to run on the linux machines at your school then you might want to code there in person, or use putty to remote in, upload your files (with svn preferably), and run it.
Yeah I heard now that Windows is a lot more tolerant with segmentation errors for example. Not even cygwin solves this problem... As I have quite a lot of work to do right now I don't really want to set up a dual boot right now and configure eclipse(I am familiar with it, would like to use it) etc.
I think I will just code and debug in Windows and regularly compile on Linux looking if anything's different
Thx guys for your help
|
On March 08 2013 04:24 KainiT wrote:Show nested quote +On March 07 2013 19:30 JonGalt wrote:On March 07 2013 19:02 KainiT wrote:Hey guys, I have a question I will have have to do a c++ project for university(most likely some b+ tree implementation) which needs to be able to run on Linux The problem is that I have Windows 7 as my main OS and I don't really want to code using a virtual os, cause the whole thing seems kinda slow, So would it be a problem to code and test, etc in Windows(probably with Eclipse) and then compile it a final time on Linux after making some hopefully small adjustements? Or would I encounter a massive amount of errors, that are hard to remove? thx for your advice  I had the same issues in university as well. I always coded in Windows using notepad++ from home. However, I would save all my work on university account using a mapped network drive and a vpn. Then using putty, I could connect to my university's linux computers where my work was saved and run it thought the putty terminal. Win win! That's pretty much what I also did until now, but as this project will be a little more complicated I would like to use the debugger, etc of Eclipse Show nested quote +misirlou wrote If you are using eclipse or other IDE that isn't Visual Studio you will be mostly fine. The only thing you need is compile the code on a Linux Machine after you wrote it and tested it on Windows. However, some libs and commands are Windows or Linux only and you will have to be careful with those. Thx for the advice, as I don't use Visual Studio and barely any libs I guess this won't be a problem. Show nested quote +obesechicken13 wrote Back in school I felt like I ran into a lot of errors when writing in codeblocks on Win7 and then compiling later on a linux machine. (I still am in school, just taking a year off).
I use cygwin a lot now because I don't like the windows command line, but I don't think anything would beat dual booting or having a dedicated linux machine. I dual boot my win7 machine with linux too. If you do have a dedicated machine, then synergy will make life much easier.
If your code needs to run on the linux machines at your school then you might want to code there in person, or use putty to remote in, upload your files (with svn preferably), and run it. Yeah I heard now that Windows is a lot more tolerant with segmentation errors for example. Not even cygwin solves this problem... As I have quite a lot of work to do right now I don't really want to set up a dual boot right now and configure eclipse(I am familiar with it, would like to use it) etc. I think I will just code and debug in Windows and regularly compile on Linux looking if anything's different Thx guys for your help
Cross compiling (compiling on one system for code to run on a different system) is a complicated thing if you don't understand what you are doing. Compilers are very capable and happy to do this, but it really slows down your development workflow because you can no longer test and debug natively. For example, target debugging driver code is possibly one of the most frustrating experiences you may have to deal with.
Virtual machines are the best way to deal with this. They can run as fast as native, but may have slightly less RAM or some driver delay. Additionally, network programming can be difficult unless you set up a bridge. I highly recommend every programmer set up a linux virutal machine if you usually use windows or osx. VirtualBox should work fine for this.
|
I didn't speak about cross compiling, just compiling on windows for easy and quick debugging purposes with an already setup eclipse distribution and also compiling the source code on linux regularly to see if I get some trouble, I don't really want to use a a virtual machine for this, everything's a little slow and installing eclipse with all the plugins I am used to work with in the virtual machine doesn't really appeal to me I guess I will eventually totally switch to Linux but for now I've made my decision
|
This was pretty funny
|
|
|
- First of all, get rid of all comments, they only make the code unreadable. - Then try to separate your elements and your actual queue. What you have defined as a queue struct is actually an element of the queue. A queue should be a struct with a size variable and an array of elements, or an array of element pointers, whichever is preferable. - Your add function should take a queue* and an element (or an element*). If you have separated queue and element, it should be clear what it needs to do. - User input should be in a separate function, not inside add. - Construction of an element should be in a separate function as well.
If you plan to continue programming, read Clean Code to get a clear picture about the single most important aspect of software engineering, and choose yourself a unit testing framework for C.
|
What's so unreadable about code? Could you explain?
|
Readable code has more structural separation and is without confusing, lying or redundant comments, for example:
+ Show Spoiler + #include <stdio.h> #include <stdlib.h>
typedef struct { short number; short priority; } Item;
Item createItem (short number, short priority) { Item item; item.number = number; item.priority = priority; return item; }
Item readItem () { short number; short priority; scanf("%hd %hd", &number, &priority); return createItem(number, priority); }
void printItem (Item item) { printf("%hd %hd\n", item.number, item.priority); }
typedef struct { int size; Item* items; } Queue;
Queue* newQueue () { Queue* queue = malloc(sizeof(Queue)); if( queue == NULL ){ exit(EXIT_FAILURE); } queue->size = 0; queue->items = NULL; return queue; }
void add (Queue* queue, Item item) { queue->size++; queue->items = realloc(queue->items, sizeof(Item) * queue->size); if( queue->items == NULL ){ exit(EXIT_FAILURE); } queue->items[queue->size - 1] = item; }
void printQueue (Queue* queue) { for( int i = 0; i < queue->size; i++ ){ Item item = queue->items[i]; printItem(item); } }
void deleteQueue (Queue* queue) { free(queue->items); free(queue); }
int main (int argc, char** argv){ Queue* queue = newQueue(); for( int i = 0; i < 5; i++ ){ Item item = readItem(); add(queue, item); } printQueue(queue); deleteQueue(queue); }
Comments like these + Show Spoiler + /* I/O */ #include <stdio.h>
/* malloc, free, realloc, exit */ #include <stdlib.h>
/* increase size */ size++;
/* get more memory for more data */ *pQueue = realloc(*pQueue, (size * sizeof(queue)));
/* loop variable */ int i;
/* point to structure 'queue' */ queue *pQueue;
/* dynamic memory allocation */ pQueue = (queue *)malloc(size * sizeof(queue));
/* deallocate memory */ free(pQueue);
/* successful execution */ return 0;
are completely pointless, you are basically just rephrasing the code below them.
Also avoid global variables like this: + Show Spoiler + /* global dynamic size of structure, it needs to be used for malloc and realloc */ static int size = 1;
What if you want more than one queue?
And again, don't mix different things in a function, like reading from the console and adding to the queue. Use one function for one thing to do.
|
Simple statements don't need comments that repeat what they're doing; that just adds extra lines of text everywhere that serves as more of a hindrance than a help. You have a comment on almost every single line of code.
/* loop variable */ int i; /* point to structure 'queue' */ queue *pQueue; /* increase size */ size++; Neither of these comments are particularly helpful, but they serve to greatly expand the physical size of the method(s), which makes them harder to read through.
Focus instead on illuminating the business logic around blocks of code.
Consider this:
/* add a member to the structure and allocate enough space for each new member */ int add(queue **pQueue) { queue instance, *tmp = &instance; short number, priority;
size++; /* get more memory for more data */ <-- This can probably go away (I don't know enough C to tell if this is a painfully obvious restatement of the following code) *pQueue = realloc(*pQueue, (size * sizeof(queue))); /* if realloc is unsuccessful, exit */ <-- Probably also unnecessary. if (!pQueue) { exit(EXIT_FAILURE); } scanf("%d %d", &tmp->number, &tmp->priority); /* qsort here */ }
It's the same code with much fewer comments, but you can still parse through it easily. You may still want to keep the comments that explain the usage of the variables you create (at my PoW we are required to do so, but my Oracle procedures can be hundreds of lines long so it makes a lot more sense than in a 15 line method). I'm ambivalent about it in this case.
|
Okay, I see your point about clean code. Thanks.
|
Here's an example snippet from one of my PL/SQL procs.
BEGIN /* Code removed */
-- Check how many records were added. 0 additions isn't necessarily an error if the file itself is intentionally empty. IF (V_NUM_RESPONSE_ADDED = 0) THEN UPD_LOG_BATCH_PROC(V_ACTIVITY, 'WARNING', 'Insert into response tables completed successfully, but no records were added.'); ELSE UPD_LOG_BATCH_PROC(V_ACTIVITY, 'DEBUG'); -- 'Records successfully loaded into response tables.'); END IF;
EXCEPTION WHEN OTHERS THEN LOG_ACTIVITY_ERROR(); END;
I've edited it a bit, but the salient point is to note how the comment illuminations business logic. Without a comment you'd be left wondering "why is 0 records inserted a warning." Frankly it could be written better, e.g.
-- Verify the number of records inserted into [myTable]. 0 additions isn't necessarily an error if the file itself is intentionally empty; otherwise, 1 or more new records should've been added
|
why does 'done' have to be public for this to compile?
class listener{ atomic<bool> done{false}; thread worker{ [this](){ while(!(this->done.load())){ this_thread::sleep_for(chrono::milliseconds(100)); } } }; public: listener(){} ~listener(){ done.store(true); worker.join(); } };
testing.cpp:9:28: error: ‘std::atomic<bool> listener::done’ is private testing.cpp:12:18: error: within this context
|
|
|
On March 08 2013 20:41 darkness wrote:C languageCode: http://www.teamliquid.net/forum/viewmessage.php?topic_id=134491¤tpage=264#5274Could you please help write a function remove() that removes an element from the structure? Alternatively, resetting number and priority to 0 like this: void rem(Queue* queue) { static int entry; item.number[entry]] = 0; item.number[entry] = 0;
entry++; }
How do I access ith element in a correct way similar to above? Thanks.
This seems like a course on data structures. Shouldn't this material have been covered in class?
We can only identify errors in your code or your logic, not write it for you.
Do you understand, and could you explain, how you would go about deleting a node in your implementation?
|
|
|
|
|
|