jephthah 1,888 Posting Maven

the answer to this question is not straightforward at all.

fgets will return everything up to and including the newline. But the problem is, that a newline character's ASCII representation is system dependent.

on *nix environments, the newline character ('\n') is typically represented as a single byte, the <LF> or "linefeed" character, ascii 0x0A. on windows and similar platforms, it is typically a double byte, the <CR> "carriage return" plus the <LF> "linefeed", ascii 0x0D and 0x0A.

However, when you add "fgets()", it becomes more complicated and depends on whether you're reading in text mode or binary mode....

when reading a file that was opened in text mode, "fgets" treats all newline characters as just a single linefeed. therefore, whether the newline character is represented as a single 0x0D, or a double 0x0D 0x0A... fgets pulls in only the 0x0A in either case as its newline. any <CR> component is silently discarded!

this makes "fgets()" problematic for binary files.

try to "fgets" the following stream: "I am a boy\n", you will receive 11 bytes: 0x49 20 61 6d 20 61 20 62 6f 79 0A, even though the newline character may be represented as 0x0D 0x0A in the original stream

when you fgets the folllowing stream: "I am a boy\r\n", you will receive 12 bytes: 0x49 20 61 6d 20 61 20 62 6f 79 0D 0A .. the extra byte, 0x0D, is actually from the '\r' character, and not from the '\n' …

jephthah 1,888 Posting Maven

^ ahaha.. your rep just went from -49 to 0 with one pity post by Dragon. LOL.

now look, here's your chance, adatapost: don't screw it up. think before you post. and get rid of your Turbo C compiler.

jephthah 1,888 Posting Maven

IDon'tReallyCareAsLongAsIt'sPeanutButter

oh, hell naw. have you had generic (store-brand) peanut butter.

dont you know? choosy mothers choose Jif.

although Skippy is pretty right-on, also.

jephthah 1,888 Posting Maven

But as for now, I would like to mention Gladiator, Troy and 300 as my favourite medival war movies :)

none of those movies are especially historically accurate, but .... medieval ?? :-O

FTR: http://en.wikipedia.org/wiki/Middle_Ages

jephthah 1,888 Posting Maven

are you using *nix?

#include <stdio.h>
#include <sys/stat.h>

int getFileSize(char *filename, long *filesize)
{
   struct stat filestats;              

   if (stat(filename, &filestats) < 0) {
   { 
      perror(filename);
      return 0; 
   } 
   else
      *filesize = filestats.st_size;

   printf(" The size of %s is %ld bytes (%3.1f KB)\n", filename, *filesize, (*filesize / 1024.0) );
   return 1;
}

.

jephthah 1,888 Posting Maven

i just recently made the switch from creamy to chunky. sometimes extra chunky.

it's like, "where have you been all my life?"

jephthah 1,888 Posting Maven

eh, scru, what?

:(

jephthah 1,888 Posting Maven

i read this as "rock paper scissor string" problem.

and thought the problem is, that "string" doesnt fit the "rock paper scissors" paradigm.

:cool:

jephthah 1,888 Posting Maven

I just remembered two movies that were quite impressive to me.

Carl Dreyer's The Passion of Joan of Arc (1928) -- imdb
Akira Kurosawa's Seven Samurai (1959) -- imdb


two of my favorites. consistently in the Top 10 of lists of best movies of all time. for the record, my wife hates them both with extreme prejudice.

there's probably no middle ground. you'll either love it or hate it.

jephthah 1,888 Posting Maven

I cannot ____ because I use Turbo C++ 3.0 IDE

are you stuck in a time machine? or is it still 1990, where you live?

throw that shit out, and join the 21st Century

If possible could you please give an example.

Code::Blocks (free)
Visual C++ express (free)
Bloodshed Dev C++ (free)

I am always ready to shift to Visual C++ Express but not until I have the answer to this question.

I am always ready to answer your question, but not until you get a modern compiler that isnt gimped

of course, then you will start having real questions for real problems, and we can just close this thread.


.

jephthah 1,888 Posting Maven

how about actually doing work when you're at work getting paid to work instead of goofing off?

jephthah 1,888 Posting Maven

there's no such thing as a truly random number. all random number generators are pseudo-random.

the difference is that some generators are better than others, in that their sequences are harder to predict than others, given current computing technology.

in other words, we have number generators that are, for all intents and purposes, "practically" random.


.

scru commented: you shut up too -1
Sky Diploma commented: True :) +3
William Hemsworth commented: blah. +11
serkan sendur commented: disapprove -1
jephthah 1,888 Posting Maven

In history, many of the great scientists changed their public hypotheses when challenged by the old Roman Catholic church. Certainly, a man would not want to die or be tortured just to prove that he/she is right.

On the other hand, many Christians would rather die, or worse, than to do the same.

What could possibly cause someone to do this, I would say much more than just a "fill-in-the-gaps" religion. Something has touched that person's heart, something obviously beyond my understanding and possibly yours as well.

In history, science has never resorted to arrest, torture, or execution of opponents whenever their hypotheses were challenged. Certainly, any reasonable man would not want to kill or torture someone just to prove that they were "right".

On the other hand, many Christians throughout history have arrested, tortured and killed other people to prevent them from presenting evidence that conflicts with their belief structure. Even today fundamentalist Christians in America would subvert the rule of law and civil liberties to squelch dissenting views.

What could possibly cause someone to do such terrible things to other humans, I would say much more than just a "fill-in-the-gaps" religion. Something has corrupted that person's heart, something obviously beyond my understanding and possibly yours as well.


.

Salem commented: Damn straight. Religion is basically a mental illness that needs to be cured. +34
jephthah 1,888 Posting Maven

i feel ya bro.

it's just the culture here is that we'd rather teach a person to fish than give them fish.

jephthah 1,888 Posting Maven

curious, did you incrementally compile 1 additional indirection operator each time? did you use a scripting language to do it?

jephthah 1,888 Posting Maven

Long story!!

yeah, it usually is, when you try and quit the internets.

jephthah 1,888 Posting Maven

if it is so simple to you write the code down
if you don't know keep your mouth shut OK

so tuff.

anyhow, i've already done it. just as an amusement for myself. it took me about 20 minutes, 10 of which was spent looking through Excel's Help files and, since i'm not a VBA person, a couple google queries on basic syntax

but if you think i'm going to tell you how to do it, you're smoking crack. how about you go and engineer yourself up a solution, mister engineer?

.

jephthah 1,888 Posting Maven

^ so.... whatever happened to June 6th?

jephthah 1,888 Posting Maven

nothing more could be added.

well... he could rewrite the entire code with full comments, perform validation and coverage metrics, compile release executables and build distribution kits for several major operating systems, then upload the packages to SourceForge and other repositories.

or he could just continue spitting out redundantly obvious answers that others had already pointed out.

either way.

csurfer commented: He will now think Oh! So many possibilities are there,it never came to my mind !!! ;) Cool one there buddy !!! +2
WaltP commented: But still a very useless post. Didn't you just complain about someone else's useless post? ;) -4
jephthah 1,888 Posting Maven

rabbi ... what? :-O

jephthah 1,888 Posting Maven

i didnt understand the second sentence either. paraphrase it for me please with easier vocabulary.

try this

jephthah 1,888 Posting Maven

if you know just help other wise don't submit a google search.

god forbid you actually take a basic thing like an excel macro with VBA and use the Excel help or Google.

:icon_rolleyes:

jephthah 1,888 Posting Maven

i have hard time understanding your english.. when you are posting a foreign speakers thread, please take it into consideration.

(1) i wasn't speaking to you.

(2) cultural references and figures of speech are commonplace. You're the ESL student, it's your job to learn them.


seeing as how you live in america, let me help you better assimilate by not catering to your incessant whining and crying

.

jephthah 1,888 Posting Maven

Saw it Sat. night at a drive-in-theater

you have a real, honest-to-goodness drive-in-theater?

like with that big metal speaker thing that fits in your window and everything??

wow....

i miss those. :(

jephthah 1,888 Posting Maven

i didnt get what you mean.

well, that's a surprise.

FWIW, my most impressive movie of my life is: UP

go see it.

now.

serkan sendur commented: anything as you do -1
jephthah 1,888 Posting Maven

wtf?

where is Lynx?

scru commented: I don't even mind people using IE in general, but if it's IE6 then we'd have a problem. +6
jephthah 1,888 Posting Maven

i just pounded out a rough scrabble game, basically just the board and tile scoring. no dictionary check, and does not account for incidental parallel tiles in the scoring. this was a fun timewaster, but i think i'm mostly done with it now.

or maybe it will annoy me late nights until i tweak it to death

either way. do what you want with it.

// SCRABBLE GAME
// by jephthah
//
// develops standard english scrabble board and allows user to 'place' 
// tiles on board ... checks validity of word placement according to 
// boundaries and existing tiles ... calculates word scores based on tile 
// values, word and letter multipliers, and existing tiles' face value
//
// to do:  	
//    score parallel tiles that incidentally form cross-words with placed tiles
//    allow variable number of players
//    assign random tiles to players per standard distribution
//    validate words to "official dictionary"
//			
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FLUSH_STDIN(x) {if(x[strlen(x)-1]!='\n'){do fgets(Junk,16,stdin);while(Junk[strlen(Junk)-1]!='\n');}}
char Junk[16]; // buffer for discarding excessive user input, used by "FLUSH_STDIN" macro

// Globals

typedef struct {
    char tile;      // current tile at board position
    int letter;     // letter multiplier (2 or 3), 0 if none
    int word;       // word multiplier (2 or 3), 0 if none
} board_t;

// board geometry 15x15
// add one extra column for print border
board_t Board[15][16];

// tile values are A B C D E F G H I J K L M …
jephthah 1,888 Posting Maven

my most abused key on this laptop is F4. Dunno why, but it got all jammed up, and i had to rip the thing out. and i've since found that laptop keys are damn near impossible to replace. :(

on my work keyboard, theres a layer of film/crud/mold/i-dont-know-what built up on my CAPS LOCK key. it's quite disgusting. i dont know what it is or how it got there, because i never use CAPS LOCK. i really should clean it off... it's pretty gross.


.

jephthah 1,888 Posting Maven

when in doubt, start simple and work your way up.

first get the mechanics of the board working. placing letters and calculating scores manually

then try implementing a simple algorithm to calculate all possible words (and their correspondign scores) given a set of letters, at one "insertion point" ... meaning, you tell the program *where* you want to attempt a word, and it returns the possible words you can put at that spot using whatever existing letters are present.

once you get that done, and i dont think that is an easy task, *then* worry about trying to generalize it across the entire board.

jephthah 1,888 Posting Maven

(1) don't use conio.h

(2) do post your questions in the appropriate forum: this is C++ code, not C

jephthah 1,888 Posting Maven

^^^ 16^2 is not 484. (!!)

^ the method to convert binary will only work on bases with a power of 2... Works for octal, hex, and base-64 (armored ascii)... won't work for decimal.

but other than the details, your methods are correct. :)


.

csurfer commented: Good catch buddy !!! Slip of keys .... ;) +1
jephthah 1,888 Posting Maven

i thought this thread was "Find CPU temperature with C code"

jephthah 1,888 Posting Maven

here, i'll help you get started:

if (month == 4 && day > 20 || month == 5 && day < 21)
    strcpy(sign,"taurus");
else if (month == 5 && day > 20 || month == 6 && day < 21)
    strcpy(sign,"gemini");
// ... etcetera ...

now don't say no one never gave you nothin'

:P

jephthah 1,888 Posting Maven

at this late stage in the game, i would not waste my time "upgrading" from 2K to XP.

If you already had XP, i'd say to keep it, but since you dont even have it, dont bother "upgrading" to something that's already on it's way to forced obsolescence.

personally i think XP is a lot better/more reliable than Vista. it's a sad state of affairs. i would not ever recommend vista. i dont know enough about Win7 to say how well it works.

if you've made it this long with 2K theres no hurry or reason to go to XP now. just wait until 7 is released and stable and go with that.

jephthah 1,888 Posting Maven

Priceless, dude. Priceless.

thanks for the lulz

jephthah 1,888 Posting Maven

miley cyrus lol

jephthah 1,888 Posting Maven

I've been putting off installing XP, but, as you say, 2k support is waning.

wow. that's some tenacity.

XP Pro is reliable, and since we already have it, i intend to keep XP on our production floor indefinitely.

But XP support will soon be disappearing. So, if you haven't gone to XP yet, then don't bother now -- skip XP, hold out another year or so, and just go to 7.

jephthah 1,888 Posting Maven

if somebody can write the code for me that do these things

ahahah. that's funny.

oh wait.... you're serious aren't you?

jephthah 1,888 Posting Maven

yeah, about 12 'if / else if" conditional statements.

jephthah 1,888 Posting Maven

you misunderstand me. a college degree does not make an engineer. "straight out of college" means nothing to me, other than they jumped through hoops. "engineer" is a professional title.

jephthah 1,888 Posting Maven

Yes. You can... "Engineer Saleh"

So, I can't help but notice you have vaingloriously put the professional title "engineer" in your name

I wonder, have you earned that right by passing a core competency professional exam or working for several years as a professional in the field?

if so, you'll have to pardon my skepticism.


.

jephthah 1,888 Posting Maven

Really? The more you talk, the more I doubt your programming abilities

well, i've got to say that it's easier to talk than to do.

admittedly, i didn't really look at the code. i got to the unknown libraries, and just stopped right there. i'm so tired of all the conio.h and whatnot, i saw three unknown libraries, i just snapped.

but good work though. I have no problem admitting you're a better -- and far more patient -- programmer and teacher than i am.

I'll also admit that this incident has taught me to slow down and take a breath before flying off about 'non-standard' libraries. i can see that they are quite trivial functions.

.

jephthah 1,888 Posting Maven

if you have to ask....

but hey, i understand where you're coming from. I'm somewhat of a Luddite, myself. i finally broke down and bought my first laptop a year ago. :P

jephthah 1,888 Posting Maven

quick note:

you've already declared 'A' as type double * ... so don't declare the type a second time when you allocate the memory

otherwise you're passing the pointer as declared correctly, but you may want to reconsider how you define the array to begin with.

jephthah 1,888 Posting Maven

what was the answer? i'm curious.

jephthah 1,888 Posting Maven

^^ thanks, A.D. apparently i need to revisit memory allocation..

jephthah 1,888 Posting Maven

the memory at the address pointed to by 'p' has been assigned the values shown. therefore, you can print the null terminated string as you might expect.

but the memory has not been allocated, so if you try to modify it the resulting behaviour is undefined.

at least that's how i understand it. someone else can clarify if i'm missing something.


.

jephthah 1,888 Posting Maven

okay, so im a jackass... yes that's been pretty well-established, and i've not made any efforts to dissuade anyone of such an opinion.

but these library headers aren't user defined. i mean that they're not unique. because apparently they're out there, somewhere, as optional features with some compiler. lets see one of you compile his code and debug it.

which is what i was going to do until i realized it was going to be an entire project in and of itself. i mean, i could do it if i had some motivation to do so, but i have other things to do besides hunt down obscure libraries, or rewrite someone elses code to use standard libraries, and I just dont have the inclination to debug 150 lines of code for someone by eyesight.

perhaps one of you fans of non-standard libraries can cipher it out.

.

jephthah 1,888 Posting Maven

i felt like i overdosed once.... "Iced King Mocha 6" had six shots of espresso. i was feeling good, so i followed it with a couple large fresh brewed coffees. then i wasn't feeling so good. i dont reckon the half pack of cigarettes helped matters.

final exams were rough that semester.

jephthah 1,888 Posting Maven

glad to hear it. the important thing is that you understand what makes the corrected version work correctly, and why.