jephthah 1,888 Posting Maven

fread statement reads the first 40 bytes from a file and puts them in a character array called buffer.

buffer is only 12 bytes in size.

this situation is generally considered to be A Bad Thing.

jephthah 1,888 Posting Maven

and would you like to give us a hint about what's not working?

jephthah 1,888 Posting Maven

are you a spammer too? or are you just daft?

jephthah 1,888 Posting Maven

crikey, eh?

jephthah 1,888 Posting Maven

and yet you bumped an 11-day dead thread to say that.

now see, this is why we can't have nice things. :icon_frown:

jephthah 1,888 Posting Maven

interesting. i'll have to look for that.

jephthah 1,888 Posting Maven

you're comparing apples and oranges. You're seeing 35 - 60+(?) minutes using the brute force on a 6x6 board, and comparing it against the algorithm on an 8x8 board. your bruteforce likely won't ever complete an 8x8 board for days or weeks.

Whereas, Warnsdorff will, on an 8x8 board, quickly find a solution from any square if you allow it to start over from the occasions when it hits a dead end. Usually Warnsdorff finds it on the first attempt, although it might take 2 or 3, maybe 4, attempts in some cases.

the failures you see with Warnsdorff occurs when it has ties in the algorithm on seemingly-equal paths to choose from. if you have it pick them at random, sometimes you wind up on invalid path that cant be predicted by the algorithm. But all you have to do is re-run the algorithm from the starting square, and the random choice picks different paths at the tie points, most likely leading to a solution on the 2nd attempt. Even if it winds up taking 3 or possibly 4 attempts, Warnsdorff still will always find a solution for each square in less than a second on a typical desktop's CPU.

the real problem with Warnsdorff is that you have no control over whether it's going to find an open solution or a closed solution, and that there's no intelligence behind differentiating between paths of equal value.


.

jephthah 1,888 Posting Maven

Are you trying to make ONE knights tour from every square on the board, or are you trying to find EVERY knight's tour that is possible, from every square on the board?

that's impossible. impossible for anyone here, at least.

there are over 13,000,000,000,000 undirected closed solutions to the Knights tour on a normal board. And an even ridiculously greater number of open solutions, the number of which is still unsolved and might as well be infinite for our purposes.

he's just trying to solve one solution at a time. bruteforce or backtracking method cant even be counted on to do a single solution on a 6x6 board in a reasonable time.

.

jephthah 1,888 Posting Maven

I want to buy purchase Dell laptop online. Can anyone tell me the reliable and recommended shop or online resource where I can buy laptop online. Need for help.

why dont you click your spam link? sure you'll find one there.


.

jephthah 1,888 Posting Maven

hi tony. do you guy use a scripting language like Perl or Python? i would think those language might help you move up in your job.

jephthah 1,888 Posting Maven

OOPS.... ^ thats wrong ^

Line #2 should read 2-- and if (b > c) note also, that the "else if" pseudo-code in line i have numbered as #6 is implied, would not be coded, and actually will result in an "else" statement that logically meets the condition b >= a , so this conditional method doesnt note the condition when two values are tied for the largest value.

other than that, the following should be correct:

(a > b) ? ( (a > c) ? a : c  ) : ( (b > c) ? b : c )

---1---   ( ---2---  -3- -5- )    ---------6---------
                                   ---7---  -8- -10-
  if      ( and if  then else )  (       else         )
                                 (    if   then else  )
Xufyan commented: thanks alot . xufyan +0
jephthah 1,888 Posting Maven

... you tell some kid to get off your lawn.

jephthah 1,888 Posting Maven

Name: Jephthah
Height: avg
Weight: working on it.
Hair: yup
Eyes: 20/20
Location: Gilead
Age: "get off my lawn"

Hobbies: smiting Ammonites

Relationship Status: yes

Fav Music: NPR, i guess. It always seems to be on :-\

Education: BS in Bovinoscatology

Work: *sigh* If I must.

Favorite Food: all the things im not supposed to eat :-(

Favorite Movies: The Life of Brian

Favorite TV Shows: sorry, I killed my television.

Favorite Miniseries: Six Feet Under was last series i watched on DVD

Favorite Video Games: i had to cancel my last MMORPG account or face dire consequences.

Stuff you Dislike: deep squats.

.

jephthah 1,888 Posting Maven

Yes, there is :)

o i c now...

some sticky thread i never read.

jephthah 1,888 Posting Maven

well, it can be optimized further using advanced numerical methods, but the optimization is geared for larger boards (or neural networks.) Any speed difference wont be noticable for what you're doing on an 8x8 board.

your assignment was probably to discover this fact that the old warnsdorff algorithm blows bruteforce/backtracking out of the water. if so, then it was a success. :)

jephthah 1,888 Posting Maven
1-- if (a > b) 
2--    and if (a > c)
3--       then "a"
4--    otherwise 
5--       then "c"

6-- else if (b > a)
7--    and if (b > c)
8--       then "b"
9--    otherwise
10-       then "c"

now see this:

(a > b) ? ( (a > c) ? a : c) ) : _______________________

---1---   ( ---2---  -3- -4- )          ( --?-- )
   if     ( and if  then else)          ( else  )
jephthah 1,888 Posting Maven

yeah, i don't know how else i would do it. backtracking is an untenable method. theres just no point even trying, IMO

some folks talk about Schenk's Theorem and Hamiltonian Paths, but I'm afraid I'm not clever enough to understand it much less apply it. And I don't have a need or care to solve a 20x20 board, so Warnsdorff is good for me.

otherwise, i've got nothing. sorry. i'll leave you with one interesting thing i just found, a very old article about the Knights Tour from Creative Computing. good luck.


.

jephthah 1,888 Posting Maven

I'll tell ya now, backtracking is the wrong way to go about it. you'll get to a 5x5 board and then the time will just grow ridiculously long.

if you searched around a bit, you would see that the Warnsdorff's Algorithm is the easiest method to calculate a solution. It's also very quick. other solutions will solve larger and larger boards, but this one will totally suffice for a normal sized board.

A couple years ago, I posted a non-recursive Warnsdorff implementation in this forum that will solve any position on an 8x8 board less than a second. you just need to think about how this algorithm. you will need to rewrite a lot of code that you have. just get used to it, i have to rewrite stuff all the time.

jephthah 1,888 Posting Maven

+1 point for using code tags. :-)

-1 point for not searching this website for one of many examples of the Knights Tour :-(


net score: neutral :-|

.

jephthah 1,888 Posting Maven

as of Dec 2008, MD5 is known to be broken. Older linux distributions used MD5. Newer ones do not.

the US Government declared

Do not use the MD5 algorithm

Software developers, Certification Authorities, website owners, and users should avoid using the MD5 algorithm in any capacity. As previous research has demonstrated, it should be considered cryptographically broken and unsuitable for further use.

--US-CERT Vulnerability Note VU#836068 (Dec 2008)


.

jephthah 1,888 Posting Maven

here's this template again. where is this coming from? some thread somewhere that tells you to post like this?

jephthah 1,888 Posting Maven

if he'd bother to pay attention in the first thread he made on this, he'd understand this already.

jephthah 1,888 Posting Maven

Xufan your codes don't work because they are wrong. Narue has given you code that works.

now do the following:

(1) read Narues post above and fully understand the second example with the if/else statements.

(2) take the first statement with teh ? : operators, and insert parentheses around them so that:
(a) the order of operations remain the same, and
(b) it is easier for you to follow the logic

you should get no more help here than this. we're not here to type your homework up and submit it for you.

.

jephthah 1,888 Posting Maven

yeah, i did it.

no, i'm going to tell you how.


.

jephthah 1,888 Posting Maven

It's more accurate to say that Notepad doesn't know anything about fonts. Notepad is worthless. Forget that it exists.

as for creating custom documents, you can use Windows OLE Automation to programmatically create and modify MS Office documents (Word, Excel, etc.) complete with font and formatting and graphs and images and whatnot.. I guess this extends to Wordpad as well, since it can open basic .RTF and .DOC files.

It's been years since I did this, and I didn't do it in C. (I did it in Perl). all i remember was it was exceedingly tedious due to a poorly-documented API, but the final result (one i finally got it) was good. But i sure wouldn't want to go through it again.

so, if you really want to do this in C, then look it up and good luck. Although, i've got to say you might want to reconsider what you're trying to do, and why.


(PS: If you really want a good text editor, I recommend TextPad. Another good one is CrimsonEditor. Either one can be set to be the default application that opens .TXT files, and it will replace Notepad for good.)

.

jephthah 1,888 Posting Maven

where you think you are? some sort of do-my-homework-for-me service?

i'd tell you to go to the Java or C++ forum, but they'd just laugh at you if you post this "gimmetehcodez" question.

when you're ready to show the work done, point out where you're stuck, and ask a coherent question, then come back.

jephthah 1,888 Posting Maven

take it to the C++ forum. they'll help you.

jephthah 1,888 Posting Maven

yeah, that's another way. i don't care for having multiple returns throughout a function, but that's a style point probably.

i guess it all comes down to style, really.

no, we're not "forced" to write programs one way or another. but some people are so hammered in with "no gotos" (especially a couple senior old-timers im thinking of) that they just can't abide any exception, and they just complain loudly and make a big deal about it.

im pretty happy with sparse use of gotos in a clean macro, as long as it can be rationalized. in this case, exception handling is necessary and i believe it makes it more maintainable and easy to debug.

I guess i was just trying to see if someone could pose a rational explanation of why I shouldnt do it with gotos, and give an elegant alternative.

jephthah 1,888 Posting Maven

here's that template again.

where is this coming from?

jephthah 1,888 Posting Maven

yeah, i try not to jump between functions, this is just to get out of any single function cleanly in the case of a hardware error.

i guess im just soliciting opinions between doing it the first way (with gotos) or the second (without). or another way i havent considered. i'd rather not use gotos because of the stigma attached to them, but i'm not seeing a cleaner way at the moment.

jephthah 1,888 Posting Maven

you dont make any sense. standard C will will work on Borland just fine.

jephthah 1,888 Posting Maven

wow, Dutch still live in SA? i thought you all jumped ship a while back.

jephthah 1,888 Posting Maven

* mwah! *

jephthah 1,888 Posting Maven

ncurses is the unix counterpart to DOS's conio. they both originated in the early 1980's. I beleive conio was basically a windows port of pcurses. they both are largely obsolete. ncurses does not do graphics any more than conio does.

use GTK+ or OpenGL libraries for graphics.

jephthah 1,888 Posting Maven

i know the general answer to using goto is always "No!". I understand why, especially when teaching basics to new programmers, because it can lead to very bad practices and horrible spaghetti code.

but ...

when i write certain hardware drivers, i have to immediately cease executing a function if an error occurs, and restore the hardware to a known state in a manner dependent upon whether and what type of an error occurred. So i find that careful use of goto can be convenient when used as part of a hardware error-checking macro

#define ErrorCheck(arg)  { errCode = (arg); if (errCode < 0) goto EXIT; }

int MyDriver_driverFunction(int whatever, char * something)
{
   int errCode = ERROR_CLEAR;   // zero (0) is no error
   // ...

   ErrorCheck( subfunction(val1, val2) );
   // ...
   
   for (port = 0; port < MAX_NUM_PORTS; port++)
   {
      ErrorCheck( anotherfunction(port, &status) );
      switch(whatever)
         // ...
   }
   ErrorCheck( somethingElse(command, response, something) );
   // ...

EXIT:
   if (errCode < 0)
      // hardware error-specific exit routines ... 
   else 
      // standard exit routines ...

   return errCode;
}

the alternative to doing it without use of gotos seems to be putting the entire function within a conditional loop that will break out early on the condition that an error is detected. I'm not sure that this is better. it looks more clunky.

int MyDriver_driverFunction(int whatever, char * something)
{
   int errCode = ERROR_CLEAR;   // zero (0) is no error
   // ...

   while (1)
   {  
      if ((errCode = subfunction(val1, …
jephthah 1,888 Posting Maven

yes. if you're on windows OS, download and install a free full-featured C development environment, with a modern compiler that is standard compliant. I recommend CodeBlocks, make sure you get the download with the "MinGW" compiler.

Microsoft's Visual C++ compiler (MSVC) is also quality, but the free (express) version is not full-featured. you will need to pay for the full package.

when someone at NIIT tells you to use Turbo C, laugh in their face and ask "a 20-year old obsolete compiler? whatever on earth for?"

if you have more specific programming questions, come to the C forum. many people there to help.


.

jephthah 1,888 Posting Maven

welcome Fribacka!

stop by the C or C++ forums, and ask questions or contribute answers as you feel suited.

jephthah 1,888 Posting Maven

hi!

jephthah 1,888 Posting Maven

okay. you got my attention. now what?

jephthah 1,888 Posting Maven

lol wut?

jephthah 1,888 Posting Maven

it's not correct to test the return value of fscanf as a NULL character. fscanf returns an int. specifically:

Upon successful completion, these functions return the number of successfully matched and assigned input items; this number can be 0 in the event of an early matching failure. If the input ends before the first matching failure or conversion, EOF is returned. If a read error occurs the error indicator for the stream is set, EOF is returned, and errno is set to indicate the error.

--opengroup.org

and EOF is a macro that is represented as a negative value.

so change your line to

while (fscanf(data, "%c%d\n",&let, &prior) > 0)

this will process as long as characters are read.

jephthah 1,888 Posting Maven

the "find" command can spill out a lot of garbage when searching from root if he doesnt have su permission. makes it difficult to find what you're looking for. you can suppress the warnings, tho i forget exactly how. you can man find for details.

but have you checked the usual suspects?

/usr/bin
/usr/sbin
/usr/local/bin
/usr/local/sbin

your $PATH variable should include these locations, at least.

the real problem here is that you need to fix your .profile so it doesnt screw up your environment variables. a sys admin, or even an experienced user, should be able to help you quicker than we will.

.

jephthah 1,888 Posting Maven

no. const and define are not the same thing.

do not attempt to re-answer threads that were already completely answered two days ago, especially if your answer is wrong.

jephthah 1,888 Posting Maven

well, yes, it's obvious. you dont' have to mince words about it. We can plainly see that he's misspelled "encrypt" in one of the encryption functions. "encrpyt" is not a word.

jephthah 1,888 Posting Maven

yeah, sorry, but I'm just totally confused, and I have to ask "why"

why does an institute that ostensibly has the purpose to train students in the latest technology, why do they insist their students use 20-year old obsolete compilers?

I mean, what's wrong with these people? Can we get an instructor or administrator from this place to explain their rationale? I really want to hear how they can justify teaching these deprecated and non-portable concepts when modern standards-compliant development environments are freely available?

It's like some kind of bizarre conspiracy.

jephthah 1,888 Posting Maven

wait, what?

someone on the internets is being a jerk?

hold the phone...

jephthah 1,888 Posting Maven

They will start you career from Turbo C & C++, bcoz there you have all the basic things that you have to learn about the programming.

that is such a bad joke. these poor students, they come to our C forum in droves, completely clueless and perpetually on the wrong track. And they're totally helpless to remedy the situation because their instructors literally FORCE them to use this antiquated, non-standard, non-portable Turbo C crap.

you'd think that a university that charges so much, would not require their students to use a compiler and development environment that has been obsolete for going on 20 years Yet they insist that they do so, and wont let them use one of many freely available modern C compiler that adhere to the standards

when you say "Start your career" you really mean "sabotage your career".. or "retard your career"

unless, as i suspect, you're just churning out telephone Tech Support operators for your mega Call Centers, then I guess it doenst much matter.

i pity your students. what a waste of money.

.

Salem commented: Well said +0
jephthah 1,888 Posting Maven

welcome!

jephthah 1,888 Posting Maven

doesn't have time to teach about <stdlib.h>? yet, will teach about <conio.h>?? i pity your class.

anyhow, what i don't have time for is looking at code that's been posted without code tags

jephthah 1,888 Posting Maven

point.

speaking of "classic errors" :$

.