jephthah 1,888 Posting Maven

Maybe there is another way of writing information into the output file.

yeah... that would be the Standard C Library command, fprintf()

not the C++ specific command you're trying to blindly force into the C program.

jephthah 1,888 Posting Maven

on linux you would just grep sysctl for a block of info

$ sysctl -a |grep therm
...

or query for the specific variable

$  sysctl hw.acpi.thermal.tz0.temperature
hw.acpi.thermal.tz0.temperature: 54.0C

on windows... i dunno. you can always find some freeware GUI application such as this, but unfortunately has no command line interface that i'm aware of.

f you can find something similar that allows command line interface, you can do a system() command to query it. which still won't help you develop a commercial application, but might do in a pinch for a personal project or internally distributed app.

if you need something more professional, you'll have to roll your own API.


.

jephthah 1,888 Posting Maven

i'm sorry, i just tried to look at this again and you've got memory allocation faults and general protection faults everywhere. i think youre trying to reallocate the same memory in different functions.

the whole thing is making my head swim... I have to admit I'm not familiar with this trie algorithm, and so I'm afraid I don't have time to devote to what would -- at least for me -- wind up being a research project.

So I'm gonna punt. maybe one of our CSC majors can figure this out


.

jephthah 1,888 Posting Maven

cfPtr=fopen("d:\\output.txt","w");

What I found is that you should append like this ...

Wrong,

You write when you want to write, append when you want to append.

in any event, it has nothing to do with access violation exceptions, as it only changes where the file pointer is located after the handle is opened.

jephthah 1,888 Posting Maven

meh, i took that quizilla quiz that John A posted a link to.

it says i'm the "Troller"

now that ain't right. i want my money back.

jephthah 1,888 Posting Maven

yeah, well i'm still wondering what kind of person chooses a screenname that deceptively suggests they are somehow affiliated with or officially representing the administration or ownership of the website they just joined.

knowwutimean, Mr. Daniweb?

jephthah 1,888 Posting Maven

as an aside....

the plan to "reset bit 5" as a method to convert a string to uppercase will make for some fun times if the string ever contains a numeral or other non-alphabetical character.

It is indeed rather "cute".

:)


.

jephthah 1,888 Posting Maven

so you're hardcoding a solution that relies on some unaffiliated third-party website maintaining precisely the same formatting and whitespace of their webpages.

yeah....... i'm gonna have to go ahead and say that's a Bad Idea.


EDIT: no wait, on second thought, I'm gonna go ahead and say that's a F--KING STUPID IDEA.

nucleon quit coding shiite for this poor noob to shoot himself in the face with.

OP: do NOT attempt to parse a website based on the number of NEWLINES the source code contains.

DO parse a website based on the keyword or tag that marks the precise location where the text that you are searching for is located.

in other words: use fgets() to read each line, then for each line use strstr() to search for the location of the keyword or tag that marks what youre looking for.

furthermore, you dont even know if there's going to be a newline between the tag and the value you want, so you may actually have to look on the subsequent line(s)

if you dont know how to use strstr(), look it up, its in the <string.h> library.

.

jephthah 1,888 Posting Maven

never mind.

jephthah 1,888 Posting Maven

strncat is doing exactly what you're telling it to: concatenating your temp string (of one character) onto the K[k] string.

the fact that you've just previously cleared that K[k] string to be empty, has nothing to do with strncat.

jephthah 1,888 Posting Maven

^ "git-r-dun" is not a recommended design process, and you will find little support for you if you recommend it.

.

jephthah 1,888 Posting Maven

i tried to compile and i got this result:

rob@rob:~/Desktop/work$ gcc palindrome.c
/tmp/cc2AgRo2.o: In function `main':
palindrome.c:(.text+0x5f): warning: the `gets' function is dangerous and should not be used.
palindrome.c:(.text+0x126): undefined reference to `strrev'
palindrome.c:(.text+0x17c): undefined reference to `getch'
collect2: ld returned 1 exit status

two problems

(1) gets? now why would do such a horrible thing? hasn't anyone told you?
(2) strrev and getch are not standard C.

the first is a warning, but the second is a show stopper. do you think someone is going to want to rewrite your code just to make it compile?

jephthah 1,888 Posting Maven

for nitc students (who might use it in 2010)

more like, for nitc students who want an example of what NOT to do.

i keep getting told that NIT universities in india are premiere. you sure cant tell by the ones who come here posting on this site.

:|


.

jephthah 1,888 Posting Maven

do you have a reading/comprehension disability or something? i'm not saying your code is wrong. i have no idea if its wrong or right because I cant read the garbled formatting that includes 3 lines of junk for every line of code.

and have neither the time nor inclination to reformat your convoluted mess.. if you cant be coherent, then dont bother

jephthah 1,888 Posting Maven

i'm sorry, what the hell do i what?

i don't know, i was just reading what you wrote.

You probably don't need lots of IR sensors.

Colin Mac commented: youre the one picking the fight dickhead +3
jephthah 1,888 Posting Maven

i have had to debug 100K lines of production code littered with GLOBALS and GOTO statements, after it had been hacked to death by every stripe of self-taught jackleg programmer.

i do not pretend to lecture experienced developers using a few sparing GOTOs. Such as yourself: you are obviously a very experienced programmer who understands the concept of writing maintainable code. Even more than me.

But I have a serious aversion to any beginner asking how to code their "hello world!" program and using GOTOs and GLOBALS to do it.

GOTOS and GLOBALS taught at the beginner's level inevitably leads to years of shiite programming that eventually has to either be continually maintained at high cost of time and labor, or just tossed out and rewritten by someone else.

i, personally, am tired of being the" someone else" who seems to keep inheriting this crap.

jephthah 1,888 Posting Maven

^ its presumptuous of you to tell him what his project needs or doesnt need. how do you know he's not building an array of IR detectors?

^^ if you want to connect with a commercial off-the-shelf IR sensor, its typically just three signal lines: RD (receive data), TD (transmit data), and SG (signal ground) *

use a DB-sub9 (aka DB-9) cable to connect the IR sensor to a RS-232 serial connector on the host computer. if you dont have DB-9 connectors on your computer you can use a USB - RS232 adapter, typically sold for ~$10 on any peripheral distributor's site.

you can also make your own cable if you need to, just get a female DB-9 connector for connecting to the PC (or the USB/RS232 adapter) , and connect a wire to each of the required signals: pin2=RD, pin3=TD, pin5=SG. the other end of the lines will connect to whatever connector allows you to connect with the RX , TX and GND of the IR device communication port.

if you're building your own IR sensor of of discrete and active components then you will need to use a UART in order to interface with the PC.

you will have to give more information about what you're trying to accomplish and what you've already done so far if you want more help.

one hint: please don't use abbreviations, or what you think passes as "chat speak". it's very hard to understand what you're …

jephthah 1,888 Posting Maven

"goto is teh EBIL!!!!!" crap is because a bunch of people were mindlessly following orders rather than thinking for themselves.

goto is teh ebil, because beginners mindlessly use it as a crutch to compensate for poorly-planned designs, and this perpetuates on into their professional work, where they cleverly develop a tangled mess of unreadable code that they only understand

then they finally realize that it's really crappy design, so they rationalize it as "job security" (with a wink wink nudge nudge),which is all funny and collegial, until they finally quit and leave the mess to be sorted out by someone else.

GOTO should be discouraged with extreme prejudice in any sort of forum that is dedicated to teaching beginners the basics of C language.

if an experienced programmer chooses to use a sparingly few well-positioned GOTOS in, for instance, some error handling routines of hardware drivers, then that's their business.

but beginners should be taught how to complete their pedantic CSC 101 programs using traditional C-language loop structures.


.

jephthah 1,888 Posting Maven

^ nice answer.

except one thing needs a bit stronger emphasis.

never, ever use "GOTO" this is not BASIC programming. You will be tarred and feathered.


(there may be an exception to the absolute ban on using GOTO, but that's not available until you reach Level 70.)

jephthah 1,888 Posting Maven

when you build your program and it complains: "warning: implicit declaration of function `memset'" ... you have to pay attention to that.

memset() and memcmp() require that you #include <string.h>

theres could be other issues, but start with that and lets see what happens.


.

jephthah 1,888 Posting Maven

so, i wonder what happens when you reach 900?

oh... never mind.

jephthah 1,888 Posting Maven

not so much. mostly, i think, it's just this dude.

but i like the way you think

jephthah 1,888 Posting Maven

come on man, dont encourage these people.

jephthah 1,888 Posting Maven

ah, nevermind... i got nothing new to add here.

jephthah 1,888 Posting Maven

i mean, is it remotely readable? look at it. think about it.

hint: the answer is "no".

jephthah 1,888 Posting Maven

why would you care if the numerator is zero? are we no longer allowed to add or muliply zero?

it seems i missed the memo ... again.

:(

jephthah 1,888 Posting Maven

OBAMA IS DE DEBIL!!!!!1

:grr: :mad: :rant:

jephthah 1,888 Posting Maven

here is a snippet of code to start. it's not going to work by itself, and i'm not giving you any secret answers. at least i hope the formula to calculate the average is not a secret to you.

now you do the rest.

for (index = 0; index < NUMBER_OF_ELEMENTS; index++)
   {
       // calculate stuff with your array here
       // ...
       // ...
       // ...
   }

   avg = sum / NUMBER_OF_ELEMENTS:

   printf("minimum: %d, maximum: %d, average: %f\n",min,max,avg);

.

jephthah 1,888 Posting Maven

how do I get the maximum, minimum and the average of an array?

sum = 0
min = value of first array element
max = value of first array element

begin loop for each array element, index = 0 to (n-1)

--- increment sum by value of array element at index
--- if array element value is less than min, set min to this value
--- if array element value is more than max, set max to this value

increment index and repeat loop til last index is completed

average = sum / number of elements (n).
max and min will hold their correct values.


.

jephthah 1,888 Posting Maven

but one limitation in this code is this only find out the integer square root of the given number

and that it's also broken code that won't compile, and doesn't even work worth a damn if you take the time to fix it.

good job on that. totally worth resurrecting a thread that's been dead for 2 years.

jephthah 1,888 Posting Maven

(1) this is C. not C++. check the forum and post appropriately.

(2) your code snippet doesn't even remotely begin to answer the question. obviously you didn't read the forum, but did you even read his question? did you even read the title of the thread?

(3) generally speaking we don't give away code for homework solutions, and we don't appreciate people who do.

jephthah 1,888 Posting Maven

how to check legality.

you have your 1D array representing the board, with array indices that represent the sequential position. 1-24 for each point, plus 0 and 25 for the bar would be how i structure it.

each color moves a certain direction, so the rolls of the dice will determine what the allowable moves are.

say white starts at point 1 and moves towards point 24. say youve got your intial pieces at setup, on points 1, 12, 17, and 19. you roll a 5 and a 6 on the dice.

white indicates that he wants to move pieces from point 1. therefore "Possible" moves could be from that point, to point 1+5 = 6, to point 1+6=7, and to point 1+11=12.

check the "possible" moves to see if other pieces are there: point #6 has more than one of the opponent's pieces, therefore not valid. point #7 is empty, therefore it is valid. point #12 has their own pieces on it, and could be valid, but there are 5 pieces there so its full and is in fact not a valid move.

to consider moves from the "bar" for white, i would consider that location 0, for black i would say location 25.

you can have several possible move results for any piece.

1- allowable, no attack. just increases the number of pieces at that point.

2 - allowable, attack. one opponent piece is alone, and will be knocked …

jephthah 1,888 Posting Maven

your first while loops searches for the first alpha char so it can be changed to uppercase.

then the second while loops changes every single remaining character to lowercase (assuming it can be changed), until it finally finds the NULL and quits.

So... instead of continuing that second while until the NULL is found, break out of that second while once another space is found. then keep repeating this pattern of capitalizing the first letter of each word as long as words are found.

note, your code as it stands is extremely fault-intolerant, and i havent even attempted to address that. because it's a whole 'nother subject. but at least youll get the basic operation figured out.


.

jephthah 1,888 Posting Maven

I'm beginning to like being proved wrong.

Hello, welcome to Daniweb. I'm the head palooka. You can join my club.

jephthah 1,888 Posting Maven

did someone say "war"?

Encoding the type of a function into the name (so-called Hungarian notation) is brain damaged - the compiler knows the types anyway and can check those, and it only confuses the programmer. No wonder MicroSoft makes buggy programs.

--Linus Torvalds
The Linux Kernel Documentation
http://lxr.linux.no/linux+v2.6.29/Documentation/CodingStyle#L237

jephthah 1,888 Posting Maven

I'm a cross between Evil Clown and Palooka.

Except, of course, when I'm being Narue's Me-Too.


(but sorry, Narue, you are not a "Godfather". That's not a fit. You're more like "Kung-Fu Master" with anger-management issues.)

jephthah 1,888 Posting Maven

well, DIAF is a little excessive, methinks. even for lazyass clowns

:(

jephthah 1,888 Posting Maven

ahh. i feel better already :)

Nick Evan commented: This thread made me laugh :) +16
jephthah 1,888 Posting Maven

holy crap did i post all that? that's ridiculous. i need to get a hobby.


.

jephthah 1,888 Posting Maven

And I did all that in only three lines of executable code

aha... but mine was fully compilable.... er, well.... for some people, probably :P

For the most part I'm just nitpicking. Aside from some awkward design choices and lack of error handling,..

thanks, narue. a good lesson was worth sticking my neck out for a beating. you might just turn me into a professional, yet.

i'm going to go present my injuries to Aia now, and soak up some sympathy.


.

jephthah 1,888 Posting Maven

the KEY POINT to understanding is this: it uses an "input pointer" (ibuf) to read the characters of the original string, and an "output pointer" (obuf) that will selectively overwrite the original string even as the input pointer is reading the same string.

One other important effect of the program to note is that this not only removes leading and trailing whitespace, but it also condenses any repeated whitespace within the string to just one space character. E.g., if you have

word \t\n  word   
^^^    ^    ^^    ^^^     (note: \t and \n are <tab> and <newline>)

it will turn it into

word word
    ^

now, I'll take a stab at splainin' the code. i think its pretty easy to understand once you wrap your head around it.

first, understand the for loop ... the logical control in the "for" loop accomplishes two tasks

--- (1) one time only, "for loop" assigns two temp pointers: "input" (ibuf) and "output" (obuf) to point to the start of the original string, as pointed to by "str", which was originally passed into the function itself and point to the actual memory location of the string.

--- (2) "for loop" will continue to execute its block of code as long as (*ibuf) is true. this means, as long as the "input pointer" is pointing to a location of the string that contains some kind of character (even a space)... just not a NULL (0)

(Opinion: this could have …

jephthah 1,888 Posting Maven

since you've marked this one solved, you might want to create a new thread on how to find min/max/avg of an array of values.

jephthah 1,888 Posting Maven

^^ aha... i think i'm somewhere between Evil Clown and Palooka

^

If it were not because you use other aliases

er, what? :-O

jephthah 1,888 Posting Maven

getting alternately beat up then nursed by two daniweb gals?

where do i sign up?


:P

jephthah 1,888 Posting Maven

OMG... i forgot to initialize "i"

line 25: int i = 0; and a more astute programmer than me reminded me that I ought to flush the output buffer. so also add for completeness:

line 28: fflush(stdout); my programming muse also pointed out that my hardcoding the sizes in "fgets" and "strftime" is also a little weak, a preferred method would be to use sizeof(.. .

and that my use of 0x0D and 0x0A instead of '\n' and '\r' is also short-sighted.

le sigh.


.

jephthah 1,888 Posting Maven

this thread fails.

[IMG] tags do not work in geeks lounge.

also, image shack does not allow hotlinking.

jephthah 1,888 Posting Maven

you know how some threads seem like a good idea late at night

... then later on in the light of day, they just seem kind of fail?

do ya?

or are you just smiling and nodding?

Dave Sinkula commented: /me smiles and nods. +18
jephthah 1,888 Posting Maven

you've "run the program" ? what program? i don't see any program.

and if you really want a suggestion, I suggest you throw Turbo C in the wastebin where it belongs. Use a real compiler that is actually used in industry. Microsoft's Visual C++ or the GNU GCC compiler.

jephthah 1,888 Posting Maven

like Narue said, your replacements have to be of precisely identical lengths. if there's any variation, even including whitespace such as tabs and newlines, you'll wreck the file.

if the replacements characters are indeed one-to-one overwrites, you will use the following commands:

"fseek()"
"fwrite()"

jephthah 1,888 Posting Maven

good effort helping this poster, but is that code ^ readable to you? if i copy and paste it, will it even compile?


.