jephthah 1,888 Posting Maven

show us what you've got so far.

jephthah 1,888 Posting Maven

yeah.

AT89s are Intel-8051 based architecture, not AVR.

the link Sinkula gave is good. here's another -- http://www.atmel.com/dyn/products/tools.asp?family_id=604

jephthah 1,888 Posting Maven

sanz, perhaps if you could post your code, we could see where you're having troubles.

jephthah 1,888 Posting Maven

"will go into a big recession"

we're already in a recession.

regardless of what Junior wants you to think.


.

jephthah 1,888 Posting Maven

i provided LINKS in the previous post.

jephthah 1,888 Posting Maven

EITHER: declare array

OR: use malloc

DONT: do both.

jephthah 1,888 Posting Maven

Reason #143 Why We Hate Microsoft.

jephthah 1,888 Posting Maven

Manvsm, to summarize what I said in your other thread, you should learn to use CODE TAGS, if you hope to get much help around here.

.

jephthah 1,888 Posting Maven

hey, Chap,

theres nothing inherently WRONG with not breaking it into smaller functions. though it might be BETTER, its not a requirement, and you shouldnt berate the questioner because s/he didnt code the way you prefer.

But I will agree, the code is nearly unreadable, yes... But that is because the poster did not use CODE TAGS.

MANAVSM, if you hope to get help here, please use CODE TAGS, and make sure you keep the indentations, so we can read what you have written.

its not because we're being sticklers to some arbitrary rule... many of us are in work or school and we dont have time to fix formatting of someones code just to read it.

i try and pop in from time to time, and give help when i can. but if i cant read your code without a lot of effort, i'll be more likely to just ignore it altogether.

just so you'll know.


.

jephthah 1,888 Posting Maven

I'd suggest to you that STRTOK might not be the best choice here. because the delimiters in STRTOK are treated equally. STRTOK takes a string and divides it up into any number of equivalent "tokens" based on the blind application of one or more "delimiters" that are used to mark the boundaries of the tokens.

For your problem, you want to differentiate between opening bracket < and closing bracket >, so you can treat the text found within the brackets differently than the text found without.

So I would instead use a couple of char * pointers to keep track of relative positions within the search string, in conjunction with STRSTR to find the next bracket location, along with a variable that keeps track of whether you are "inside" a tag (because the last bracket found was '<') or "outside" a tag (because the last bracket found was '>')


.

jephthah 1,888 Posting Maven

eh, that was my second guess...

:P


but that makes me wonder... do you have a hangup with the word "pop" then?

jephthah 1,888 Posting Maven

(1) fflush and fgets are two totally separate things, and completely independent of each other.

(2) fflush is only meaningful for "stdout", as im sure Dave's link explains.

(3) the code you have that someone "said it worked" will not work any better than your original code. if you enter an invalid input, it will still blow up on you.

.

jephthah 1,888 Posting Maven

aha. now we're getting somewhere.

i'll bet you live near the atlantic seaboard around VA or NC or thereabouts.

jephthah 1,888 Posting Maven

i wish threads that have had no activity for 90 days or more, would be automatically locked.

Aia commented: I vote for that. +8
jephthah 1,888 Posting Maven

good points -- i stand corrected.

one day i'll learn about relying on "memory"

.

jephthah 1,888 Posting Maven

on the one hand, i like the compactness of Sinkula's code (i sometimes code like that), but on the other hand, it doesnt lend itself very well to readability for people not used to the style

int mygetd(double *result)
{
   char buff [ 32 ]; /* modify as needed */
   return fgets(buff, sizeof buff, stdin) && sscanf(buff, "%lf", result) == 1;
}

It might help you if we break out the "return" statement a little bit for readability.

So here is an example of his code broken out to an extreme degree. I normally wouldn't write such tedious code for a simple function, but this might make it more clear as to what the operations grouped in his "return" statement are actually doing.

int mygetd(double *result)
{
   char buff [ 32 ]; /* modify as needed */
   numBytesRead = 0;
   isValidValue = 0;

   numBytesRead = fgets(buff, sizeof buff, stdin) 
   if (numBytesRead>0)  // format value, pass back as "result"
      isValidValue = sscanf(buff, "%lf", result);

   if (isValidValue == 1) 
      return 1;  // value entered is good
   else
      return 0; // no valid value found
}

To understand how his combined return statement works, you can follow it by the C operators' order of precedence...

first the "fgets()" function is performed, if it evaluates as TRUE, then the "scanf(...) ==1" function is subsequently evaluated (note, the == 1 is redundant). if it also evaluates as TRUE, the entire function returns TRUE (1), and the variable "result" is passed …

jephthah 1,888 Posting Maven

dont include the type declaration (Modeldim) when you actually call the function. only use that when you declare the array to begin with.

and when you want to pass an array, you dont use the address operator &, because the unindexed array actually is a pointer to the start of the array.

myfunction(array) ... is the same as .... myfunction(&array[0])

int main()
{
   int x,y,z;
   Modeldim array[100];   // 'declares' the array

   myfunction(array);    // calls the function and passes the array into it

once you call a function, the locally-defined variables are no longer visible. "array" as it was defined in main, is not visible to "myfunction"... the only way it is accessible is when you pass it into the function as an argument. at which point you must reference it according to the "name" that the functions "sees" it as:

void myfunction(Modeldim *submodel)
{
   submodel[0].x = 10; submodel[0].y = 10; submodel[0].z = 10 ;
   submodel[1].x = 20; submodel[1].x = 20; submodel[1].x = 20 ;
   submodel[2].x = 30; submodel[2].x = 30; submodel[2].x = 30 ;
}
jephthah 1,888 Posting Maven

that's ridiculous.

say you're going to the store. you ask your friend "what kind of ______ do you want"

you dont name off every possible brand and flavor of soft drink.

so quit being obstinate, and answer the damn question.

jephthah 1,888 Posting Maven

my work computer has an obama sticker on it. prominent. so everyone coming down the hall sees it.

i know it annoys the republican whose office is caddycorner from mine. it's right in his line of sight.

:D

jephthah 1,888 Posting Maven

HAY GUISE

whats going on here?

jephthah 1,888 Posting Maven

lets stare deeply into each others eyes for long moonlit walks on the beach!

MM PJM ND NS HWP ISO BI or G C or LDS BBW LD LS OK DDF a plus GSOH and SI for FTA send photo YMMV RTFM PEBCAK OMG LOL TTYL


.

twomers commented: NaCl H2O... you're just making chemical symbols and you know it! +6
jephthah 1,888 Posting Maven

oops

jephthah 1,888 Posting Maven

you forgot a main category: "drink"

you pretty much just left out the entire Southeast US on that.

EDIT: hmm.. looking at your map link, maybe generic "drink" was particular to VA / NC / SC....

personally I hate the word "pop" used for soft drink... it sounds so ridiculous.

.

jephthah 1,888 Posting Maven

im kind of a moderate, so i guess i dress down the center.

scru commented: ... +3
jephthah 1,888 Posting Maven

I do not know if this has ever been asked in C before but

only about a million times :P

other than that, the link Aia gives is pretty solid. anything i might add would just be pedantry.

jephthah 1,888 Posting Maven

if you declare a variable or array in one function it will be readily available within that function, but it will not be visible (available) to another function unless you "pass" it (or a pointer to it) to that function via an argument. this is the concept of "locally-scoped"

if you declare a variable or array globally (outside of all functions) it will be equally available to any function. Warning: "Globally-scoped" variables are very tempting, but are generally a bad idea -- for many reasons -- and you should avoid using them.


.

jephthah 1,888 Posting Maven

you've only declared the type of the structure.

you havent declared any actual arrays.

you have to declare an array of type "Modeldim" within the main() routine.

int main(int argc, char *argv[])
{
   int X=Y=Z=1000;
   int i,j,k;
   int NUM=10 ;
   Modeldim submodel[100];

this creates an array of 100 instances of the Modeldim structure. you can then pass the array (or a pointer to the array) to the function that would modify it.


.

jephthah 1,888 Posting Maven

DOH!!

i knew that... really i did.

yes, you're right... never use gets().. always use fgets().

im sorry, that was a typo/accident. i didnt bother to proofread it for some reason.

jephthah 1,888 Posting Maven

am using turboC

thats the root of all your problems. stop it.

get the free MS Visual C/C++, or CodeBlocks with MinGW (GCC) compiler.


Upgrade to modern compiler and learn to program the real way. Turbo C was nice in its day, but like me its day has come and gone.

not true! you, my friend, are a font of wisdom and experience. quite a valuable resource indeed.

Turbo C, on the other hand, died long ago and only continues to roam this mortal plane by some unholy alliance with the developing second-world nations.


.

jephthah 1,888 Posting Maven

you cant "fflush" an input buffer.

the best thing to do is not use "scanf", but instead use "gets", and parse the entire string for everything that's entered, whether it's valid or garbage or a mixture of both.

jephthah 1,888 Posting Maven

Hello.

I'm sorry, but what is your question?

jephthah 1,888 Posting Maven

good articles, thanks. added to bookmarks

i actually found a workaround:

margin: 0px;
*margin: 0 0 0 -2;

'*' causes it to be ignored by FF, but still parsed by IE

not pretty, but hey, it works for now

jephthah 1,888 Posting Maven

Disclaimer: I am not a webdesigner by any means, i only know enough to get my self into trouble.

Im trying to help a non-profit fix their webpage, and Im having a rotten time getting IE and Firefox to agree. the front page is a 3x3 grid of pictures that link to other pages. (some of the pictures are 2x wide).. it works just fine in FF -- all pictures are flush against each other. But IE keeps adding whitespace between the pictures within each row.

ive been hacking and poking at this a while, but nothing i do seems to make it better.

please help, thanks!

<!-- // FROM HTML FILE // -->

<div id="main_imagemap">
<div class="img">
<a href="involved.htm"><img src = "images/nw.jpg" align="left"></a>
<a href="video.htm"><img src = "images/nn.jpg"></a><br>
<a href="outlook.htm"><img src = "images/ww.jpg" align="left"></a>
<a href="about.htm"><img src = "images/ce.jpg"></a><br>
<a href="projects.htm"><img src = "images/sw.jpg" align="left"></a>
<a href="aboutus.htm"><img src = "images/ss.jpg" align="left"></a>
<a href="news.htm"><img src = "images/se.jpg"></a><br>
</div>
</div>


<!-- // FROM CSS FILE // -->

#main_imagemap 
{
   position:absolute;
   top:130pt;left:50pt;width:790;
   z-index:6;
}

div.img img
{
   display: inline;
   margin: 0px;
   padding: 0px;
   border: 2px solid #000000;
}
div.img a:hover img 
{
   border: 2px solid #F7EF6A;
}
jephthah 1,888 Posting Maven

HOLY SMOKES

I'm glad i got out of this thread when I did.

(i saw it coming)

jephthah 1,888 Posting Maven

IIRC,

it prints the two 'a' characters, then it backspaces to the point between the two 'a' characters that were just printed, then it prints a newline.

so the two 'a' characters remain, and the cursor is on the new line.

the backspace does not delete a previously printed character. you would have to overwrite it if you wanted that to happen. the new line just moves the cursor to the next line, it does not delete any chars or carry them along with it.

youre just printing to a terminal screen, not a word processor. try the following and you should see what i mean. printf("\naa\b \n"); unless, of course, i'm just wrong and dont know it yet.


.

jephthah 1,888 Posting Maven

I wanted to create an algorithm that finds every possible Knight's Tour from any given position in a reasonable amount of time. I'd like it to be in a minute, but I'm not sure if that's possible.

um, yeah, good luck with that.

there are 26,534,728,821,064 possible CLOSED solutions to the Knight's Tour on an 8x8 board, plus an as-yet uncounted number of undoubtedly many orders of magnitude greater than that for the OPEN solutions.

check these guys out for help: http://www.cray.com/products/xt5/index.html , and meanwhile, Ill keep an eye out for your results when you're published in the journals.

:P


.

jephthah 1,888 Posting Maven

i dont have my code available to me here at work, its on my laptop at home.

all i did was write code to implement the Warnsdorff Algorithm. its a couple hundred years old, and it's no secret.

you could implement it yourself and get the same results i did.

http://web.telia.com/~u85905224/knight/eWarnsd.htm

the pros of this method is that it's accurate (~98%) and its FAST. when i said 15 milliseconds or less, that was the maximum total time to find one solution per square, for ALL of the 64 squares in succession. so, approximately 250 microseconds per solution, or less. (and actually that was on my laptop, an AMD Athelon X2 (2.something GHz per core)

the real flaw with it is that it won't find all possible solutions, which may be unacceptable depending on your requirements. it can find multiple solutions per square, some closed and some open, but it wont find them all.


.

jephthah 1,888 Posting Maven

this is not a verbatim example that you should blindly copy.

this is an "OUTLINE", of general functionality, that give you a top-level overview of how the program goal can be accomplished.

you have already written the "user_input" function, for the most part. break out the part that initializes the Array with asterisks and put that in a function such as "initialize_seat_array" so that it is only called once before going into the do/while loop.

then in the do while loop, write a function that prints the array as a matrix to the screen, prior to each time "user_input" is called.

finally, it is considered bad form to PM people with requests for private help. post your questions in the public forum and wait for one or more people to reply with public answers.

jephthah 1,888 Posting Maven

Why does it matter what speeds I'm getting?

why so hostile?

i want to know if its worth my time to post my solution. if you're getting speeds as fast as mine, i wont bother.

anyhow, the Warnsdorff algorithm, as ive coded it, solves each of the 64 positions on the board in 15 milliseconds or less. This is a 1.8 GHz machine.

mind you, this is just "solving" any given position. I could keep running it at that rate indefinitely, but if i had to keep track of unique solutions, it would add some overhead.

jephthah 1,888 Posting Maven

before i go any further, i want to know what kind of speeds you're currently getting. time per solution.

also, do you require closed solutions, or are open solutions acceptable?

jephthah 1,888 Posting Maven

its really hard to read, since you don't use code-tags, and all the indentation is lost...

but it looks like you're only running through the routine once.

think of this sort of program flow:

int main()
{
   initialize_seat_array();

   do
   { 
      print_seat_matrix();
      result = user_input();

   } while(result);
}

where the program flow is broken into three main functions.

(1) -- first you initialize the seat array to all asterisks (*).

then you enter a do/while loop that

(2) -- prints the seat array as a matrix on the screen, then
(3) -- queries the user to request a seat assignment.

if the user gets the seat assignment, the array element for that seat is set to 'X'. the loop repeats immediately, back to (2), printing the new state of the seat matrix, and (3) querying the user for another seat request. etc. etc.

the do/while loop continues (2) and (3) indefinitely, until the user indicates they have no more seat assignments to request, at which point "result" will equal zero, and the loop will exit, and the program ends.

.

jephthah 1,888 Posting Maven

no you don't. I was wrong. As Dragon pointed out,

const int row= 12,seat= 5;
char plane[row][seat];

is correct because you're using the "const" (constant) modifier.

Sorry for the confusion.

your only issue remaining, is printing the correct info to the screen and formatting it, using the "cout" commands. see Dragon's post #13, above, for a good suggestion.

you're doing just fine. keep at it.


.

jephthah 1,888 Posting Maven

i answered this question in the other thread.

in the future please don't double post the same question in two different threads.

jephthah 1,888 Posting Maven
const int row= 12,seat= 5;
char plane[row][seat];

this is wrong. you cant use variables to declare the size of an array like that. try:

char plane[12][5];

you can then *access* the array using variables, like youre doing with the "y" as row, and "x" as seat.

i think you're on the right track.

jephthah 1,888 Posting Maven

I'd like to state for the record, that I agree with Ed, Nick, Dragon, and Jishnu the Second.


.

Nick Evan commented: Nice to know that you sometimes actually agree with someone ;) +6
jephthah 1,888 Posting Maven

"FLOAT CODE" is meaningless.

do you want to know how to display floating point values?

or do you want the IEEE 754 Standard for binary floating point arithmetic?

jephthah 1,888 Posting Maven

yes, you're quite right. thanks for noting that, it will probably help someone looking at this later :)


.

jephthah 1,888 Posting Maven

will it output juct like this??

no, you need to figure this out, dude. its basic "cout" statements.

you say you're studying electrical engineering? you better reevaluate your motivations because you're not going to make it through a semester of EE classes with a helpless attitude.


.

jephthah 1,888 Posting Maven

really, man, if you're going to be an electrical engineer someday, you need to learn how to approach problems methodically without all the whining and crying.

:icon_rolleyes:

seriously. Arrays -- 2-D and otherwise -- are freshman material. theres a concept you should become familiar with, it's called: Look It Up


.

jephthah 1,888 Posting Maven

actually, MATLAB uses ANSI C code.

<io64.h> is not a standard C library -- obviously -- but I believe it's fully compliant with ANSI C.

check it out before you make any conclusions. I think it's what you need.


.