Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

Or perhaps it's metrics like this which make google think there are a lot of content-free threads.

Posting Games; Threads=162 Posts=56,143

Salem 5,265 Posting Sage

Well the easy answer is to upgrade to a 32-bit compiler for your modern OS, then you get 2GB segments, not 64K segments.

But I'm guessing you're stuck with stone age tools from a stone age educational system.

The answer (if you can call it that) is to NOT have all your code in one singularly massive .c file. There's more to it, but it might be enough of a clue. Someone else will have to expand on this, or I might get around to it later on.

Salem 5,265 Posting Sage

> The main thing is to contribute good quality postings, ask interesting and relevant questions and answer threads where you know the answer.
Perhaps you should just delete the entire http://www.daniweb.com/internet-marketing/25 tree, which seems to consist mostly of low quality link spam to dubious MLM marketers and other related scams.

jingda commented: Agreed +0
Nick Evan commented: Yes! +0
Salem 5,265 Posting Sage

no <- have you searched google -> yes

Salem 5,265 Posting Sage

> At console I enter 0238284, then all the printfs outputs 0.
When did 8 become a valid octal digit?

Salem 5,265 Posting Sage

Seems like the sort of thing that should be testable in a couple of minutes - did you try it?

> Also specify the order of precedence for variables when they need to be accessed.
Again, something that google will easily find 1000's of pages with the operator precedence table.

Salem 5,265 Posting Sage

It depends on how you correct your spelling mistake.

http://en.wikipedia.org/wiki/Ellipse
If you want to draw a mathematical figure on screen.

http://en.wikipedia.org/wiki/Ellipsis
If you want to know how something like printf(const char *format, ...); works.

mrnutty commented: exactly what I thought +13
Salem 5,265 Posting Sage

> or is the setting j on zero only change, cause i tried that already but it doesn't work.
No, the other change is changing <= into <

Post your latest code.

Salem 5,265 Posting Sage

Scotch on the rocks.

iamthwee commented: Now that's a drink... Jack Nicholson in The Shining. +0
Salem 5,265 Posting Sage

> void main () main returns an int, not void.

> for (int i=1; i<=row; i++) Every for loop is wrong. Arrays start at 0, not 1
So for (int i=0; i<row; i++)

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

Facebook IS the scam.

http://www.mattmckeon.com/facebook-privacy/
Click through the years, see how the blue "privacy" (joke) spreads with the passing of years. Between their screw-ups, and your ignorance, you may as well just jump in a tar pit, run through a quilt factory and have a big "kick my ass" sign tattooed on your arse. You deserve to be ridiculed and kicked at every opportunity.

The rest is just decoration for the cake.

jwenting commented: well said +0
Salem 5,265 Posting Sage

For an easy intro, try http://www.arduino.cc/

For hardcore programming down on the "bare metal", http://www.avrfreaks.net/

All I can suggest is you read around and follow some links to board manufacturer sites to see what meets your needs. There are a lot of variations to choose from.

Salem 5,265 Posting Sage

You buy space and time from a hosting provider.

There's plenty of ads for them over here
http://www.daniweb.com/forums/forum154.html

A shell account might be more appropriate
http://clusty.com/search?query=shell+accounts&sourceid=Mozilla-search

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

> #include<malloc.h> /* You need this if on UNIX or LINUX */
This is all wrong.
malloc is prototyped in stdlib.h

> p = (char *)malloc(sizeof(words));
You don't need to cast malloc in C programs.

Have you tried it without the cast? Did you get any error messages?

These perhaps?
"implicit conversion of int to char*" -> you didn't include stdlib.h
"conversion of void* to char*" -> you're using a C++ compiler to compile C code.

> 4. sizeof() ; function says it all . It means size of the "data" in this case "words".
sizeof is an operator, not a function.
Passing an array to a function yields a pointer to the first element of that array.

The parentheses are optional when applying sizeof to a variable.
p = malloc(sizeof words );

Other issues:
- you didn't check malloc for success
- you didn't describe free(), the essential complement to using malloc.

Salem 5,265 Posting Sage

Eclipse doesn't make sound - it's an editor wrapped around a compiler.

What matters is what your OS is, what API's you have access to and the kind of programs you're creating.

Eclipse runs on many platforms, and can generate project types for many different programs.

So explaining say "sound for a Linux console" wouldn't make a damn bit of use to you if you're interested in "windows GUI programs".

Salem 5,265 Posting Sage

*unsort = malloc(sizeof(char)*strlen("\\!Unsort"));
strcpy(*unsort, "\\!Unsort");

Yeah, you need to malloc (strlen(foo) + 1 ) bytes to copy a string foo.

The fact that it works with certain strings (and it's still wrong) just makes you lucky.

Salem 5,265 Posting Sage

Break it into steps

1. Find files

cd /root/projects
find PROJECT* -type f > $HOME/allProjectFiles.txt

Gets you something like this

$ cat $HOME/allProjectFiles.txt
/root/projects/PROJECT01/date/JAN2000/output/SAMPLE0001/TARGET_102932
/root/projects/PROJECT02/date/JAN2001/output/SAMPLE0002/TARGET_32323
/root/projects/PROJECT03/date/JAN2001/output/SAMPLE0003/TARGET_32999293

2. Extract ones of interest $ awk -F'/' '$6 ~ /JAN2001/' $HOME/allProjectFiles.txt > $HOME/selectedProjectFiles.txt Now you can make the condition in red as complicated as you want.
You can match literal strings, or regular expressions. $2 == "PROJECT01" && $6 ~ /JAN200[0-4]/ being the PROJECT01 files for January for the first half of the decade.

3. Copy files $ cat $HOME/selectedProjectFiles.txt | while read line ; do echo cp $line ${HOME}/TMP ; done When you're happy that the printout of copy commands looks good, just delete the echo and it will actually do the copying.

Salem 5,265 Posting Sage

Load first map from file
Play level
Load second map from file
Play level

If loading a map takes a few seconds then
Load first map from file
Play level
Display some static image and play "tension" music in the background
Load second map from file
Play level

jonsca commented: Rep for recommending the "tension" music -- good touch +4
Salem 5,265 Posting Sage

Well if you showed us how you declared and initialised your array, then we could tell you how to pass it to a function.

Hint: just copy/paste the original declaration into your function prototype.

Salem 5,265 Posting Sage

> while (elements[j] > elements[j+1])
j starts of as n-1, which means j+1 is actually n (which is also off the end of the array.

Also, what's stop the j=j-1 going negative?

Salem 5,265 Posting Sage

> while(nextPermutation(elements,n));
But you marked the function as returning void.

You need to return a value indicating if there are more permutations.

Salem 5,265 Posting Sage

> pSinglePoint = &next;
Two things wrong here.
1. You're attempting to point from inside the class, to some outside the class. A class object should be a self-contained entity. Having invisible dependencies to the outside world is a recipe for disaster.
2. You're actually storing a pointer to the local parameter, NOT the original in main.

Salem 5,265 Posting Sage

Because passing an array to a function reduces it to just a pointer to the first element, and the size information is lost.

Just like it were a regular function.

Salem 5,265 Posting Sage

How can something be 99% complete AND have a major issue at the same time?

Salem 5,265 Posting Sage

> Why does this happen?
Because TCP is a stream protocol. All it guarantees is the order of the information. Breaking that into packets is your problem.

You might send
"hello world\n"
"bye world\n"
in two separate send calls

but on any given test, you might get
"hello world\nbye"
" world\n"

or
"h"
"ello worl"
"d\nbye"
" world\n"

or any other fragmentation.

The point is, all the information is as you sent it, just broken up into different sized packets (specifically, NOT the ones you sent).

> How to solve it?
Find some way to encode the packet information into the sender, then use that at the receiver.
- a delimiter like \n perhaps
- or a size followed by payload.

Salem 5,265 Posting Sage

> What compiler are you using that flags the operator error? As far as I know, I have a fairly modern compiler

$ cat foo.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv[]) {
  if ( argc = 1 ) {
    printf( "Mmm, interesting...\n" );
  }
  return 0;
}

$ gcc -Wall foo.c
foo.c: In function ‘main’:
foo.c:6: warning: suggest brackets around assignment used as truth value

$ cl /W4 /nologo foo.c
foo.c
foo.c(5) : warning C4100: 'argv' : unreferenced formal parameter
c:\temp\foo.c(6) : warning C4706: assignment within conditional expression

gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3
Visual Studio is 2008 vintage.

Salem 5,265 Posting Sage

Most of the IDEs I know save the compilation/interpretation to external tools.

So a simple wrapper around
- edit file using an editor
- pass file to compiler
- gather error messages.

All of this is mundane stuff compared to writing a compiler.

Maybe grab the source code for code::blocks and start reading.

Salem 5,265 Posting Sage

Your class is missing a ; after the closing }

Salem 5,265 Posting Sage

Your default Node constructor makes sure it is empty (in a way the rest of your Node class will recognise).

Salem 5,265 Posting Sage

Try Node *Node_array = new Node[5]; or Node *Node_array = new Node[someNumberOfNodesYouWant];

Salem 5,265 Posting Sage

> It reduces the likelihood of accidentally using an assignment statement (a = 1) instead of an equality statement (a == 1)
Or it increases the likelyhood of making a mistake when you have (var1 == var2), and no amount of rearranging the code will save you.

Plus, a lot of people find such code to be highly unreadable.

Further, operand swapping zealots also extend this to the relational operators as well (<, > etc), where there is absolutely no value in doing so. I've seen people introduce BUGS into working code because they made a mess of it.

Most modern compilers will diagnose use of = in an if statement right off the bat, without having to mess with the code at all. And this includes the important edge case where rearranging fails.

http://c-faq.com/style/revtest.html
It's from a time long ago when compilers only had error messages, and blindly generated code so long as it was syntactically correct.
If you're still using such a compiler, consider upgrading.

Salem 5,265 Posting Sage

> for(int i=1;i<4;i++)
This doesn't initialise ALL the elements.

> bmpHeader.BitsPerPixel=24;
You've said the format is 3 bytes per pixel - so why are you writing 4?

Padding for 4 byte alignment (Could be a value other than zero)

You forgot to take into account this little detail.

Generally, you need to assemble a byte array yourself, then write that out.
Pointing at some struct is generally a bad approach, even when it seems to work.

Salem 5,265 Posting Sage

Sure - but what about the "1 second" bit of the problem?

Salem 5,265 Posting Sage

Why does ONESEC fall through to CLEARALL ?

Salem 5,265 Posting Sage

I remember seeing such things when trying to compile C code with a C++ compiler.

Though to be honest, there are better choices for getting a GCC compiler on windows nowadays (http://www.codeblocks.org/)

Salem 5,265 Posting Sage

> while(input[k]=getchar() != '\n')
Precedence

You wrote
while(input[k]=(getchar() != '\n'))
which just assigns boolean 0 or 1 based on the logical test.

You want
while( (input[k]=getchar()) != '\n')
which assigns the character read to the array, then compares it.

Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

It's how 0x69 posted in post #8, only using fgets() to read the line in place of scanf.

But you've had 2 days and 10 replies, so now it's time to focus.

Salem 5,265 Posting Sage

Reading the whole line using fgets(), then using either strtok() or sscanf() to parse the line would be my suggestion.

Trying to spot the \n with scanf() would be messy.

Salem 5,265 Posting Sage

> but if I call malloc every time, it would be a memory leak wouldn't it?
It would actually seem simpler.
If rows and cols are variable each time around the loop, then allocate / do stuff / free might be a lot simpler.

realloc is for when you're say reading a file, and you want 10,20,50,100,1000... items (the size just keeps growing, and you have no idea where to start).

Also, if you have a reasonable upper bound to the sizes, then just allocating the max for everything at the start would save a lot of work in the loop.

Salem 5,265 Posting Sage

Do you know the difference between "jump" and "call" ?

and your code looks exactly the same, only with worse formatting.

Salem 5,265 Posting Sage

You're jumping to rather than calling PROCs

Maybe
call @G01
jmp done


Where done is a label at the end of your if/elseif chain.

Salem 5,265 Posting Sage
1>------ Build started: Project: Manual Stack Implementation, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
[B]1>stack.cpp[/B]
1>Linking...

Have you ever seen it compile stack.cpp ?

If not, you need to add it to the project.

kvprajapati commented: solved. +9
JasonHippy commented: Salem FTW! +2
Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

> By the way, just use the strncpy() function. strncpy_s() is non-standard, non-portable, not a good choice to use.
And the use of either in a C++ program (when the OP has already used std::string for something) is just bone-headed :)

EVERY char array and char* needs to be turned into a std::string (or a reference to one).

Salem 5,265 Posting Sage

> cmd_info->infile = malloc(strlen(args) * sizeof(char));
You need strlen(x) + 1 chars to copy a string.

Salem 5,265 Posting Sage

> But howcome this code works perfectly fine in Linux?
Pure dumb luck - that's all.
In another programming scenario, it would be Linux crashing and windows working as expected.

To gain some measure of confidence, you need to use additional tools.
Eg. valgrind ./myprog or gcc -o myprog prog.c -lefence ./myprog Both of these will run your code with additional memory checks, and cause a crash (even better if you're in the debugger at the time - showing you where).