jephthah 1,888 Posting Maven

look... the QUESTION that the original poster asks is, essentially, should he learn Assembly or should he learn C.

I'm saying this:

you can be a good C/C++ programmer, and do a lot of "real" work -- embedded or otherwise -- without having to know the deep dirty secrets of Assembly programming

Contrariwise, you can NOT just be a good Assembly programmer, and reasonably expect to do any meaningful projects in the real world, without having solid C skills.

C is therefore *primary* to Assembly and should be emphasized with prejudice over Assembly.

15 years ago (maybe even 10) the world was a different place. You could still argue the primacy of assembly over C for embedded. But the world has changed, and the changing technology of C compilers has caused a complete paradigm shift.

you can either move along with the change or get left behind.

so my advice to beginners is: learn C now, worry about assembly later. And this is coming from someone who learned (and loved) assembly first.

that is all.

.

jephthah 1,888 Posting Maven

LOLWTFBBQ

jephthah 1,888 Posting Maven

nah. i took the tax reserves and a private jet to the Maldives. those are just rumours i heard whilst sipping rum drinks.

jephthah 1,888 Posting Maven

and technically you are stupid if your gonna try and take a test to destinate if you acually are stupid.

destinate?

nice.

feelin' pretty smart, are ya?

jephthah 1,888 Posting Maven

good thing about shotguns is that if you're close enough you can still hit the target even if your aim is lousy.

jephthah 1,888 Posting Maven

by just using the "e" format, you'll get standard scientific exponentiation, but it might not be exactly what you're looking for

for instance if you specify 2 decimal places like so: printf("%.2e",myDoubleValue); your example values will be printed as 1.20e-5 and 1.31e13 it will not force them along standard "engineering prefix" exponent values (groups of 3, like 'kilo' 'mega' 'micro' 'nano' etc.) ... your example values seem to suggest that might be a requirement for you. If so, the problem becomes somewhat more complicated. if not, then the %e format specifier is sufficient.


.

jephthah 1,888 Posting Maven

i tried this once but it was lacking in immediate gratification.

i think my nation eventually depleted their resources and turned to cannibalism, but i'm not for sure

jephthah 1,888 Posting Maven

well, i think im pretty stupid.

i spent damn near a half hour, first taking the test, then cycling through about 50 freakin adverts to get the results without giving any info, or giving false info. i finally quit and didnt get anything :grr:

but my consolation is that im not as stupid as someone who tried twice, or (god forbid) someone who actually gave their legitimate address or email.

jephthah 1,888 Posting Maven

yeah fun stuff, but you'd better not be initiating those pranks from inside the U.S.

the FCC has started prosecuting people who send phone pranks from the Internet under a provision of the Wagner-Folsom Act of 1977, the so-called "Anti-War Dialing Act".

http://tinyurl.com/2g9mqh

.

jephthah 1,888 Posting Maven

wow! we're going BOWLING???

w00t

jephthah 1,888 Posting Maven

lol. dont start with Salem about void main.

not only is it his raison d'ĂȘtre ... but he's right


.

jephthah 1,888 Posting Maven

lol. i love these threads, only because it tends to be my own M.O.:

post a question for help, then while waiting for responses to trickle in, go about trying to solve it myself anyhow. sometimes just formulating the question reveals the answer.

:)

jephthah 1,888 Posting Maven

cool thanks, so what are the stars, then?

jephthah 1,888 Posting Maven

... this whole reputation points and altering power business works...

ive got like 70-some-odd points, but i still only have one little green box, and 1 altering point.

I'd sure feel cool if i could get a few more green things ... it'd also be nice to know what the basic formula is, so it doesnt seem so arbitrary.

I dont know if this is appropriate question for the "geeks lounge", but i figure anyone who gives a damn about their e-Rep on an internet forum, has got to be a geek in the eyes of most of the world.

thanks

jephthah 1,888 Posting Maven

okay, i agree with you on what i think are your points:

(1) there are still some people, somewhere, doing meaningful work in assembly.
(2) programming microcontrollers does require some "understanding" of how it works at the assembly level (but NOT for programming entire functions in assembly)
(3) there will always be a need for the occasional macros, such as precision timing, to be coded in assembly

but the point im trying to make, relative to the OP's question on which language to learn, is that

Assembly should be learned only after you have a solid command of the C and C++ fundamentals.

because, unlike 15 years ago, C compilers today produce highly efficient machine code for embedded microcontrollers in a way that has made 95% of the Assembly programmers and their arcane bag of tricks completely redundant.

the beginner will get the most return on their investment by learning C and C++. ... virtually no one hires entry-level assembly programmers. they do hire entry level C and C++ programmers. so learn to crawl, walk, and run before you learn to fly.

another very important thing Dragon noted earlier, is that if you learn Assembly first, you have to UNLEARN all those techniques that are useful only in Assembly, and make horrible, horrible practice for C and C++ ... like the heavy use of jumps and gotos, for instance.

.

jephthah 1,888 Posting Maven

PICs and 8051 derivatives are mainly programmed in assembly.

i dont mean to keep carrying this off into a tangent, but that's just plain not true

8051 derivatives have been being programmed in C as far back as 15 years ago, starting with the old Keil compiler. and thats just as far back as I remember.

sure, there are still sunday-afternoon hobbyists and students in poorly-funded classrooms who may program blinking-LED projects for their PIC's in assembly

but as far as industry goes... tons of embedded apps use PICs, 8051s and similar GP controllers in complex applications ... and it would be absolute *suicide* for any competitive company to try and program them in Assembly. you'd never get your product to market in any reasonable time, and maintenance would be cost-prohibitive

think about it, when a C compiler costs a few hundred dollars, what kind of business would be crazy enough to pay the manhours required for a staff of assembly coders?

look im not saying there arent any Assembly coders out there gainfully employed. but they're the exception, not the rule. the majority of assembly you see these days are short little macros, sparsely placed

hammerhead commented: Agreed, I have been programming uC's all in C +2
jephthah 1,888 Posting Maven

ah, that's a good hint :)

too bad i dont use visual studio. :(

jephthah 1,888 Posting Maven

one problem jumps out: if (wset[mset[i].menPreference[mset[i].proposeToW]].free ... your "mset.proposeToW" evaluates to the value 4, and then is used as an index for another arrays with only four elements.

that's a run-time ARRAY OVERFLOW error.


.

jephthah 1,888 Posting Maven

is it normal for you to write your code in this manner? what i mean is, do you intentionally refuse to indent your code, and purposefully line all your brackets up against the left wall?

because you see, im trying to debug your code -- I truly think this in an interesting puzzle -- but damned if it isnt frustrating as all hell to try and read it all smashed up against the left margin.

so rather than thinking about your code, all i can think of is, "why did he do this? do i want to go and insert 100 <tabs> in this guy's program, just so i can read it? ... is this what i want to do with my time?"

already I've spent 15 minutes in frustration plus typing this complaint. If i wasn't intrigued bythe problem i would have just quit looking at it and ignored this thread altogether.

jephthah 1,888 Posting Maven

im not sure what kind of microcontrollers you mean, but the ones i deal with ... scientific instrumentation and medical products ... are all programmed in C.

now there's always an occasional macro in assembly, but they're short and sweet, and few and far between.

assembly programming is a rare skill these days, because the demand is but a fraction of what it was 10 or 15 years ago.

jephthah 1,888 Posting Maven

i should have qualified "assembly was the first language in which i did any meaningful work" ... i just played with the others. Basic/Pascal/Fortran are, for all intents and purposes, completely useless languages -- unless you're an Excel Programmer (Basic) or a Nuclear Engineer (Fortran)

...

i was going to say that i program eeproms using C... if driving external hardware to manipulate data bit-by-bit, counts... probably not. i guess you've still got to understand basics of low level assembly programming.

but that should all be secondary to first learning the higher level languages like C/C++ ... assembly should come later.

.

jephthah 1,888 Posting Maven

well, i just learned something.

jephthah 1,888 Posting Maven

i learned assembly years ago as my first language (not counting BASIC, Pascal and Fortran, which i never did anything meaningful with)...

in the early 90's it was important to know Assembly to do embedded programming, because the C compilers for embedded controllers were terribly inefficient -- and expensive if you were a student or hobbyist. the "Assembly is Better" mindset continued even into this decade.

But now the C compilers rock, and only the most specialized apps or processors would ever need such low-level programming.

so, as some one who learned on assembly, and loved all its peculiarities.... I hate to say it... stay away from Assembly if at all possible. at the very least, don't start learning to program on it, for reasons Dragon pointed out already.

do yourself a favor and learn C and learn C++... C is especially suited for microcontroller and embedded work, while C++ in particular will give you the Object-Oriented foundation on which you can expand in any other direction as needed.

dont bother with C# unless you are immediately going to go work in a Microsoft shop. Definitely do not get bogged down in some Macintosh "objective c".... no one uses Macintosh for C programming in the industry, that I've ever seen. i mean, if you want an object-oriented version of C... it's already here: it's called C++. And it's portable to any OS. Vendors reinvent the wheel because they want to lock you into their proprietary 


jephthah 1,888 Posting Maven

i'm not sure what your question is.

jephthah 1,888 Posting Maven

yeah, i just saw it. for the benefit of others who may have similar problems -- and for the benefit of yourself, in case i give you an incorrect answer -- please do not try to take this thread into the private sphere.

post your updates/comments/questions/remarks/solutions here in this thread.

thanks

jephthah 1,888 Posting Maven

what did you expect it to do?

you're trying to do the close and tell function on a NULL pointer.

now think about that for a minute, and you should have your answer.

.

jephthah 1,888 Posting Maven

fix the errors and repost your code, then i'll try to run it again and see if it works according to the specs you described.

jephthah 1,888 Posting Maven

well, it doesnt compile.

you cant do anything regarding debugging until you at least get it to compile

C:\Users\jezebel\Documents>cl marriage.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

marriage.c
marriage.c(66) : error C2065: 'Man' : undeclared identifier
marriage.c(67) : error C2065: 'Women' : undeclared identifier
marriage.c(67) : error C2146: syntax error : missing ';' before identifier 'engageSet'
marriage.c(67) : warning C4552: '/' : operator has no effect; expected operator with side-effect
marriage.c(95) : error C2065: 'man' : undeclared identifier
marriage.c(95) : error C2146: syntax error : missing ';' before identifier 'mset'

C:\Users\jezebel\Documents>

.

jephthah 1,888 Posting Maven

i wont be able to get to it tonight, too much to do... tomorrow, though.

jephthah 1,888 Posting Maven

i think this is an example of "obfuscated code"

perl programmers also love to do stuff like this.

jephthah 1,888 Posting Maven

i can compile it and run it through some tests, if that's what you're looking for?

jephthah 1,888 Posting Maven

lol. these posters never cease to amuse me.

jephthah 1,888 Posting Maven

glad we could help

:)

jephthah 1,888 Posting Maven

everyone who's ever gone through UDP and TCP socket programming has these issues.

as one of many who had to slog through it on my own, i can say that you'll love yourself better if you solve it yourself, rather than someone to tell you how to do it.

if it helps, you're on the right track and are almost there.

FWIW, Winsock2 (and even 1.1) is pretty solid, and well documented. it makes you almost want to like Microsoft until you recall that they copied it damn near wholesale from the BSD.

meh, whatever. it works well.

http://msdn.microsoft.com/en-us/library/ms740673%28VS.85%29.aspx

jephthah 1,888 Posting Maven

this thread made me laugh.

jephthah 1,888 Posting Maven

o i see. that's gotta suck. i guess i remember now, back in early 2000's, when a particularly nasty virus went around our university (a major state research institution) .... it really wreaked havoc on everyone for a good month or so. the good thing was, they finally got some competent security people in the sys admin department after that.

so this exercise of yours wasn't a homework assignement? just a personal project?

oh, and thanks for the comment. :)


.

jephthah 1,888 Posting Maven

theres no "learning" visual c. if you're using the free MSVC compiler, it's still just C...

MS compiler and libraries still has non-ANSI portability problems compared to GCC (linux) but given MS history, it could be a lot worse.

it at least doesnt introduce addtional problems such as what Borland does.

sorry about your virus problems. i doubt it has anything to do with college.

i still don't quite understand what you were trying to do... were you trying to solve "EVERY" possible solution from each of the 64 squares? the closed solutions alone number around 26,000,000,000,000 solutions.

i dont think you're going to get that accomplished anytime soon on your old Dell PC.

jephthah 1,888 Posting Maven

its hard for me to understand exaclty what you're doing.

are you trying to solve the knight's tour, once for each of the 64 starting positions?

does it matter whether the solution is open or closed? what exactly are you storing and recovering in the text files?

because there are literally trillions (million-millions) of closed solutions. i cant imagine you needing to provide more than one solution for each starting square.

if it helps any, each 64-round "tour" should be easily solved by the computer program in less than 5 seconds, and thats just overhead for various I/O. without printing to screen, should be much less than 1 second.

if it's hanging on you, you've got some major problem(s) somewhere, probably an infinite loop.

jephthah 1,888 Posting Maven

for windows development, i use the Microsoft Visual C compiler. The "Express Edition" is completely free, and its the industry standard if you're developing PC apps. you can get previous versions (like 2005) if the 2008 doesnt work with your machine.

GCC would be the one for linux/unix

i mean, but hey, if you've got a project due, and you're allowed to use non-portable non-standard libraries like CONIO and BIOS... and you're used to workign with them, then dont change right now

just be aware, that these libraries will continue to haunt you and eat your soul until you exorcise them from your life.

as for my code, its working now just fine. and solves the Knight's Tour from any position on an 8x8 board in a few seconds .. would be a lot faster, but i display the board and moves to a terminal display, and that slows it down a lot.

but i can't just go and give it to you. that would defeat the point of you learning how to write your own code to solve problems.

all i did was use the old Warnsdorff's Algorithm. the algorithm itself is pretty simple, and has been around for some 200 years, to solve this exact problem.


.

Prabakar commented: It was very helpful +1
jephthah 1,888 Posting Maven

i wouldnt use bios.h either. it's just as bad.

why are you using such non-standard libraries, anyhow? is there a reason?

if you were maintaining mountains legacy code, say, on old crusty Win98 machines, i could see the reason behind sticking with it. (i had the misfortune of being in that situation a few years back...)

but if not, you should really drop these borland/windows archaic libraries like a bad habit.

....

Upon further review, i was able to extract your <conio.> dependent code and everything compiled okay.

ive since written an entirely new program from scratch, just to satisfy my curiosity. its not quite bug free, but i did it only using the STDIO and STRING libraries.

jephthah 1,888 Posting Maven

in "main", declare an integer array of size equal to or greater than the number of possible lines, initializing all elements to zero on startup.


each time you go to use a line, check to see that the array element at that line index is still zero. if not, choose a different line.


once you use a line from the file, set the value of the array element at that line's index number to one.

jephthah 1,888 Posting Maven

its like deja vu or something.

jephthah 1,888 Posting Maven

i want to help you, but youre using non-standard C that wont compile on either GCC or MS Visual C

you should never use Borland's CONIO functions.

so im either forced to port your code to something the rest of the world can use, or ignore it entirely and move along.

jephthah 1,888 Posting Maven

sure. instead of using "rewind", merely close the file, then reopen it exactly as you did the first time.

either way you start at the beginning of the file. rewind is just a nicer way to do it.

PS: dont be afraid to try new functions. especially if they're part of standard ANSI C libraries. rewind is part of the <stdio.h> library.

it's not some sort of secret 33rd level Grand Poobah Royal Order of Ancient Waterbuffalo thing.

jephthah 1,888 Posting Maven

dragon's is a very nice and concise example of how to pass a float to a function.

here's how you could fix your code to work as it is.

int object1 = 100 ;
   int object2 = 1000;

   float object_f1 = (float)object1;
   float object_f2 = (float)object2;

   float *ptr_object1 = &object_f1;
   float *ptr_object2= &object_f2;

the concept here is called "casting", where you cast a variable of one type to another.

regardless, the pointer still has to be a type float.

i prefer dragon's method, its much more elegant. i'm just putting this out for illustration.

jephthah 1,888 Posting Maven

well, for one thing:

size_t i=0; /*counter for loop*/
	int len; /*length of line from file*/

you've got your types switched. not really going to make a difference (size_t is typically #defined as a long int) but still...

if this basic stuff is wrong, i wonder how much more typos and cut-and-paste errors are lurking.

jephthah 1,888 Posting Maven

"help a little more"

how can we help you if you dont give us any thing to work with.

you cant plop down the description of a problem, and say "help me fix my program to work better" and then not even show us WTF you've been doing?

post your program here.

and use [code] tags. if you dont know what [code] tags are, find out before you post.

jephthah 1,888 Posting Maven

if you're using winXP, you should NOT be using some old crusty DOS compiler

MSVC is given away free by Microsoft.

get it. use it. love it.

jephthah 1,888 Posting Maven

ack.

i put a semicolon after the "while" statement in line #11 of my function.

sorry, i dont know how it got there. but it put you in an infinite loop. remove it and it will work as expected.

it will also be technically more correct to declare the argument to the "delay" function as time_t void delay(time_t seconds) although it will work just fine as an INT... unless your delay time requirements exceed 68 years.

jephthah 1,888 Posting Maven

this is a simple and imprecise and not even remotely thread-safe, but it should do for you for now.

void delay(int seconds)
{        
    time_t start_time, cur_time;

    time(&start_time);
    cur_time = start_time;

    // delay will rarely ever be the full amount specified.
    // specifically:    (seconds-1) < delay <= (seconds)

    while((cur_time - start_time) < seconds);
        time(&cur_time);      
}

usage: #include <time.h> ... delay(3); // the average delay tends towards 2.5 seconds.