jephthah 1,888 Posting Maven

Heres their program's header file

/**
 * StopDice.h
 * Defines  constants used for StopDice program logic and graphics
 *
 * NOTE that string constants are NOT declared constants in order
 * to conform to the requirements of WinBGIm functions that do 
 * not define constant string parameters when they should. This will
 * be fixed when WinBGIm is itself fixed.
 *
 * @author . . .
 * @version 1.0 May 2008
 */
 
/*------------- Program Constants ------------------*/
char GAME_NAME[]   = "Stop the Dice";
char GAME_CLAIM[]  = "- Extreme Challenge!";
char GAME_INTRO1[] = "* Stop with 2 dice showing the same value => Score 1 point";
char GAME_INTRO2[] = "* Stop with 3 dice of the same value => Bingo! add 1 and multiply by value";
char GAME_INTRO3[] = "Press the [Space bar] to start or stop";

const int DELAY        = 160;/* milliseconds between dice rolls */
const int NUM_DICE     = 3;  /* number of dice displayed        */
const int NUM_IMAGES   = 6;  /* number of different dice images */

/*------------- Graphics Constants -----------------*/
const int IMAGE_SIDE    = 142; /* pixel length of a die side */ 
const int WINDOW_WIDTH  = 4 * IMAGE_SIDE;
const int WINDOW_HEIGHT = 2 * IMAGE_SIDE;
const int IMAGE_TOP		= IMAGE_SIDE / 3;
const int IMAGE_BOTTOM	= IMAGE_TOP + IMAGE_SIDE;
const int BK_COLOR      = WHITE; /* Screen background colour */

and the program's source code

/**
 * StopDice.c
 * Implements the "immortal" StopDice game
 *
 * @author . . . 
 * @version 1.0 - May …
jephthah 1,888 Posting Maven

oh, well that changes things. you're talkign about the Windows API that handles windows events.

In that case you should not be processing any data in WndProc, itself. Ideally this function will only be used to report what actions the user has performed on the window. specific data processing should be handled by other (non-callback) functions.

in any event, this thread was a general discussion about *why* globals should not be used, not *how* globals should not be used. Perhaps your problem would be better served in its own specific thread.


.

jephthah 1,888 Posting Maven

here you go:

#define GIT_R_DUN   3.00
#include <stdio.h>
#include <math.h>
int main()
{
   double x = GIT_R_DUN;
   printf("root of %f = %f\n",x,sqrt(x));
}

if questioned, tell your professor that NO ONE in the "real world" writes this stuff from scratch, then ask him if he's ever had a "real job". If he still complains, send him here to talk to me.


.

jephthah 1,888 Posting Maven

SOMENAME:

C does not lend itself to easily extracting and replacing arbitrary text from a file. you can do it, only if the field from which you are extracting/replacing is a FIXED WIDTH. there can not be any variation in the width of the text field.

if thats the case, then you can use a combination of functions like FSEEK, FTELL and REWIND.

if its not the case (and it tends to not be the case for typical applications), then you will need to:

--open the original file for reading
--open a new file for writing
--read orig file one line at a time, modifing as needed
--write that line to the new file.
--when done, delete the original file
--rename the new file with the original file's name.

sucks, i know. if you really need to get into serious text file manipulation, you might look into Perl. but that's a whole 'nother can of worms.


.

jephthah 1,888 Posting Maven

WHOA, whoa, whoa... Clockowl.

That is so, SO wrong, I dont know where to start.

Did you even try this? have you ever tried this?

of course not, it would never even remotely work. It doesnt even make SENSE.

IMHO, you need to read more and help less. a lot less.


.

jephthah 1,888 Posting Maven

no, i would declare a normal struct in the program that *calls* WndProc (most likely, your "main" routine) and, from there, pass a pointer to the struct as an argument to WndProc


.

jephthah 1,888 Posting Maven

i dont ever write pseudocode, so i have no idea what the formal structure is supposed to look like, but if someone held a gun to my head and said "GIVE ME PSEUDOCODE"

... then here's how i would start.

define structure named GRADES
   with string element NAME
   with integer element TEST1
   with integer element TEST2
   with integer element TEST3
define integer Index = 0

while Index is less than MAXIMUM
{
   getstring username
 
   if username equals "ZZZ" 
      then break from while loop

   otherwise
   { 
      set GRADES[index].NAME = username
      set GRADES[index].TEST1 = 0
      set GRADES[index].TEST2 = 0
      set GRADES[index].TEST3 = 0
   }
}

if Index equals MAXIMUM 
   then print "Grade Structure Is Full!"


(etc., and so on)

something like that

.

jephthah 1,888 Posting Maven

why don't you just pass a pointer to a struct into the function?

jephthah 1,888 Posting Maven

okay, first thing you should do is look for "command line interface" in the documentation for your cam. once you find that, then look into the C command, "system()" ... if your cam has no command line interface you may want to consider getting your money back and finding one that does.

i am leaving soon and will not be able to follow up with this until later tonight.

im sure there will be a solution. just keep plugging at it.

jephthah 1,888 Posting Maven

I actually have a robort on which a camera mounted.I need to write a C code in that robort's embeded system so that it will be able to capture an image autonomously when a condition is satisfied.And then I will store the image , compress it and transmit.

that sounds pretty cool

i'm going to first admit, i have never done anything involving this, so i'm making some semi-informed guesses.

what is the make and model of the web cam? is it a COTS device? do you have latitude in choosing which device to use, or are there a few devices that have been spec'd?

jephthah 1,888 Posting Maven

Not to be an asshole but poster says he wants to capture and store image data from a webcam. That's pretty specific, not?

the surest way to know when someones going to be an ass, is that they preface their statement, "not to be an ass, but ...."

Okay, here's the deal, ass: I've learned in my short time here that new posters tend to trickle out details of their requirements, little by little.

Y'see, ass, im trying to shorten the process a bit. Does he really just want to blindly snap pictures, ass? Or is there going to be some sort of dynamic feedback control?

Either way is fine, ass, but before i go too far in looking for a solution, I want to understand the full problem.

.

jephthah 1,888 Posting Maven

if you're just trying to send commands to blindly operate it, then the easiest (as in "hackiest" and least-portable) way to do this is to send the camera system() commands

this requires that you know the command line interface to the webcam... and that it even has one.

jephthah 1,888 Posting Maven

what are you trying to do exactly?

start and stop a webcam, or engage some of its other functions, just in an automated fashion?

or will this also involve interpreting the image files in some manner?


.

jephthah 1,888 Posting Maven

(1) i dont answer unsolicited PMs for programming help

(2) you didnt read my reply, did you? Because if you did, you would Start a new thread

jephthah 1,888 Posting Maven

can u give me da code in "c"

if you weren't purposely talking like a braindead AOL chatroom luser, i might actually "give u da code".

jephthah 1,888 Posting Maven

you mean you just want a variable to be "represented" as an "exponential value" that you can then perform some ____ operation upon?

well that's meaningless because theres no such thing, really.

theres essentially only two types of variables: integers and floating points

an integer variable type is just a numeric value ultimately held in machine code by transistor switches, most easily conceived as values of ones and zeros. how you want to "represent" them (binary, octal, decimal, hex, ascii char) is superficial, and meaningful only to the human reading them.

floating points are also just some machine code represented by transistor states (on/off, one/zero), but they have the additional complexity of being divided up into fields for sign, mantissa, and exponent. (exponent offset and binary point are implied.) How you want to "represent" them (standard decimal or scientific exponent) is likewise superficial and only meaningful to the user.

printf and sprintf are the constructs by which you are able to format how variables are "represented". How you choose to do so is your own business and has no effect on the variable itself.


.

jephthah 1,888 Posting Maven

will the above code work in dev C compiler?

who knows? this thread FOUR YEARS OLD and is about a Turbo C program that was probably 10 years old when the thread was written.

Please also tell me how to capture ,store and read images using dev C. It is urgent

No it's not urgent.

your lack of foresight in starting your homework assignments constitutes no urgency on our part to go dig through some crappy old TURBO C program.

look here, son, going through life stealing other peoples programs off the internet without any understanding of what you are doing is going to come back and bite you in the ass, and hard.

And I'm not going to be the one to give you rope to hang yourself with.

you need to define your own problem, start coding your own ** solution, and then --- when you get stuck --- start your **own thread using coherent questions and posting your own code using CODE tags.

and if you're using Turbo C, which i fear that you are, do yourself and the rest of the world a favor, and throw that crap into your recycle bin and get a REAL compiler.

jephthah 1,888 Posting Maven
jephthah 1,888 Posting Maven

Excel 2003 has both LOG() & LOG10(), why would the LOG() in spreadsheet be log10() in C?

because EXCEL is written mainly for people who don't really understand undergraduate-level mathematics, whereas C is designed for all sorts of folks, including engineers, scientists and mathematicians.

the natural logarithm, sometimes written as "ln", is the logarithm to the base e... all other logarithm bases are arbitrary, whether it's base 2, or base 10, or base 27.3 ... just because you have 10 fingers and think base 10 should always be implied, doesn't mean that's the case for the natural sciences, engineering, or even finance.

so C is universal in its application of logarithmic bases.

log(x) is the natural log of x.
log10(x) is the base 10 log of x
log2(x) is the base 2 log of x

if you want to use any other base, fine: use the simple property of logarithms to change the base to any arbitrary value b

logb(x) = log(x) / log(b)


.

jephthah 1,888 Posting Maven

um, okay... thanks?

jephthah 1,888 Posting Maven

i just realized this thread was 2 years old

oh well, whatever. here's a guy's webpage for making a beep in linux. http://frank-buss.de/beep/index.html

i have no idea if it works.

jephthah 1,888 Posting Maven

you might try format precision specifiers if you want to reduce the number of decimal places. for instance, "%.2f" will round it to two decimal places, dropping any trailing zeros in the fractional part.

1234.56
24.68
0.9

even better, "%8.03f" will round it to three decimal places, keep any trailing zeros in the fractional part, and keep the entire number right-justified within a constant 8-character-width field

1234.556
  24.680
   0.900

you could also do scientific exponent format if the values are particularly small or large. For instance, "%.3e" will print (up to) three significant decimal values in exponential format, dropping any trailing zeros

1.234e3
9.86e-9
...etc...

and you can likewise use zero-padding and/or field width placeholders as described above.

--http://www.cplusplus.com/reference/clibrary/cstdio/printf.html

.

jephthah 1,888 Posting Maven

you want the source code for the standard C library? ok, here it is: http://ftp.gnu.org/gnu/glibc/glibc-2.7.tar.gz

now please do feel free to go and knock yourself out. and if you can manage a specific, coherent, targeted question, I'm sure someone will try to help you.

but please don't feel free to repost entire source code files saying, "hay guys, how's all this stuff work?"

.

jephthah 1,888 Posting Maven

lich, if youre going to help,

(1) learn to indent your code properly
(2) learn to use tags

and for the record, your code is horribly fragile and will break if someone looks crosseyed at it.

.[code=c] tags

and for the record, your code is horribly fragile and will break if someone looks crosseyed at it.


.

jephthah 1,888 Posting Maven

if (pow<0)
ans = 1.0/ans;


fractional powers would be more fun.

:P

jephthah 1,888 Posting Maven

i agree, there is a memory leak.

disappointing i know. you so wanted it to be either a flaw in MSVC++ or perhaps in malloc itself. I know, ive been there.

but take this as a lesson, right now, to quit using malloc in programs where the need for extended runtime is critical .... or better yet, quit using it at all.

it doenst make you a better programmer because you can use it. in fact, it tends to be inexperienced and/or sloppy programmers who use malloc most often. 99% of the time i see malloc used, it is completely unnecessary and could be just as easily avoided, and half the time it's implemented poorly.

this is not 1995 any more. RAM is cheap and readily available. if you just absolutely have to use malloc, use it only in tightly controlled situations.


.

jephthah 1,888 Posting Maven

i would never use malloc() where longterm runtime stability is critical.

that said, i don't understand how you can so easily rule out a memory leak.

yes, i hear what you're saying about how your available memory appears to be ~1GB... but to use that sort of indirect observation to necessarily rule out a leak, well... that's a dangerous assumption.

as Salem so insightfully noted, 8000 * 256K = 2G ... now THAT is highly suspicious. One might even go as far to say that is the sort of evidence for a memory leak.

at any rate, to so cavalierly rule out a memory leak off the top is IMHO crippling your ability to discover root cause.


.

jephthah 1,888 Posting Maven

^ yeap... i agree pretty much with everything you said there. (except i think perl is pretty easy for beginners to get started, at least for the basics...)

and FORTRAN is dead. but it also still runs the majority of our nation's nuclear power plants. not bad for a dead language.

i still love Perl, it's amazingly powerful and adaptable.

i think im just annoyed that 5.x has been around for 14 years, and they've been promising 6.0 "any day now" for the past 7 or 8.

jephthah 1,888 Posting Maven

lol

jephthah 1,888 Posting Maven

i'll bet that, as part of the homework requirements, he's not allowed to use the <math.h> library

jephthah 1,888 Posting Maven

i assume you want to *print* a large float or double value in scientific notation.

double myLargeNum;

 ...

printf("value = %.2e\n",myLargeNum);

http://www.cplusplus.com/reference/clibrary/cstdio/printf.html


.

jephthah 1,888 Posting Maven

when you start thinking that standard C libraries are "misbehaving", you need to take a step back and recheck your assumptions.

the most likely problems are

(1) a bug in your own code
(2) you dont understand the function like you think you do
...
(3) a distant but possible reason could be that you're using some crappy free compiler you found from some sketchy website. If you're doing that, well... stop doing that.

what you're NOT going to find is evidence of "misbehavior" in an ANSI C library.

jephthah 1,888 Posting Maven

okay, Walt, i see what you're saying about casting with type long in order to round

but now you're answering this question not as originally presented, but based on a subsequent question from a future post that did not exist at the time this question was posted.

so, i have to admit I was neither able to see into the future nor able to read the poster's mind.

...

It would also sure reduce a lot of confusion if the POSTER would keep his questions regarding the same problem in the same thread.

.

jephthah 1,888 Posting Maven

Au contraire, mon frere.

your response, on the other hand, needs to be reviewed

jephthah 1,888 Posting Maven

Yes he does, and yes it does.

No he doesn't and no it doesn't.

Walt, %lf is only meaningful for *input*... it is undefined for output

And furthermore, I am not attempting to intuit the "whys" and "wherefores" of his formula, whether it's correct or incorrect for his overall purpose. I am only showing "how" to accomplish what he asked: and that's to fix the forumla he has given to provide the correct answer as it is presented.

he shall get the answer he wants -- according to the formula he has presented -- by losing the long type cast.

that is all.

.

jephthah 1,888 Posting Maven

you just posted this problem yesterday, and I answered it.

http://www.daniweb.com/forums/thread125124.html

if the answer is not sufficient, please continue to address your questions in your original post. Please don't clutter up the forums with multiple threads on the same problem.


.

jephthah 1,888 Posting Maven

looking back at this now, it wasnt exactly clear as to what the heck the OP wanted.

jephthah 1,888 Posting Maven

I'm using MS Visual C++ 2005 Express Edition

then, of course, you will change the compile description to match how you do it in MSVC. the command line instruction, for instance, is simply

cl myprogram.c

jephthah 1,888 Posting Maven

oh... it has a MinGW-included setup

aha, i missed that. i used a direct link to the vanilla setup.

sorry

I'll shut up now

:$


.

jephthah 1,888 Posting Maven

okay, i dont know how far youve gotten, but your first problem with the original code is your confusion of the structure elements with independent variables.

here's what i think your intent is... try replacing this first part of your program, recompile and work on making the rest of your program follow this scheme.

(and more than replacing, try to understand how the structure elements are being referenced... i believe you did it correctly in your "student" example above)

struct library 
{
	char title[40];
	int isbn;
};

int x, found,count,y;
struct library book[30];

void setup()
{
	strcpy(book[0].title,  "Wind In The Willows");
	strcpy(book[1].title,  "Fright Night");
	strcpy(book[2].title,  "Women From Venus,  Men are from Mars");
	strcpy(book[3].title,  "Happy Days");
	strcpy(book[4].title,  "Gone Fishing");
	strcpy(book[5].title,  "My Sql");
	strcpy(book[6].title,  "About Nothing");
	strcpy(book[7].title,  "Beowulf");
	strcpy(book[8].title,  "Shopoholic");
	strcpy(book[9].title,  "Programming for Leraners");
	strcpy(book[10].title, "I love You");
	strcpy(book[11].title, "cardinal");
	strcpy(book[12].title, "The Birds");
	strcpy(book[13].title, "Three Men and Mice");
	strcpy(book[14].title, "Stig Of The Dump");
	strcpy(book[15].title, "Nowhere");
	strcpy(book[16].title, "Zulu");
	strcpy(book[17].title, "Deal with It");
	strcpy(book[18].title, "Klaxons");
	strcpy(book[19].title, "Learn to speak Spanish");
	strcpy(book[20].title, "");

	book[0].isbn  = 1234777372037;
	book[1].isbn  = 2345109283274;
	book[3].isbn  = 3456280364781;
	book[4].isbn  = 4567982745729;
	book[5].isbn  = 5678111882763;
	book[6].isbn  = 6789120356788;
	book[7].isbn  = 7890999243552;
	book[8].isbn  = 8901188826666;
	book[9].isbn  = 9012224563728;
	book[10].isbn = 0012312222112;
	book[11].isbn = 0112344882773;
	book[12].isbn = 0122309412036;
	book[13].isbn = 0132300098765;
	book[14].isbn = 0142333387887;
	book[15].isbn = 0152322229999;
	book[16].isbn = 0162322222000;
	book[17].isbn = 0172311993873;
	book[18].isbn = 0182333333221;
	book[19].isbn = 0192300000000;
	book[20].isbn = 0;

	count=20;
}

.

jephthah 1,888 Posting Maven

if you ever work on any big project you're going to be in trouble.

because if you have to work with any coworkers who develop code the right way, they're going to make you look bad ...

then people will curse your name after you've left (or been asked to leave) your job and your code is handed off to future developers/maintainers.

here's a hint: "struct"


.

jephthah 1,888 Posting Maven

are you just trying to delete the numeral characters from a string?

then do something like this

void deleteNumerals(char *mystring)
{
    char *str_ptr = mystring;
    while(*str_ptr)
    {
        if (*str_ptr<'0' || *str_ptr>'9')
            *mystring++ = *str_ptr;
        str_ptr++;
    }
    *mystring = '\0';
}

just note that the string being pointed to will be modifed in place, destroying the original. if you need to keep the original string, save a copy of it before calling the function.

.

jephthah 1,888 Posting Maven

hmm... rechecking this... i dont think Code:Blocks comes with a compiler. it comes with the *ability* to use multiple compilers, but you have to provide them. if you dont provide your own, it defaults to expect the GCC compiler which, as far as I'm aware, doesnt exist on windows.

AFAIK, the only GCC-style compilers that works on windows are MinGW and Cygwin, and you've got to go get them yourself.

For Windows users, the easiest/quickes way to get started is to use the free MSVC compiler, Code:Blocks will detect it automatically. (downside is no debugger available with the free compiler)

MinGW might be a better option, tho I havent tried it yet. I briefly tried to get it to find my Cygwin GCC implementation, but haven't had time to work it out.

personally i just use MSVC with CodeBlocks on my windows machine (or just plain old Cygwin if necessary), and I use GCC with CodeBlocks on my linux machine. one day ill spend some time and make them more compatable.


.

jephthah 1,888 Posting Maven

so... what's your question now?

i tried compiling your original file from post #1 and i got about 100 errors.

jephthah 1,888 Posting Maven

source code is not "kind of like a programming code"... source code IS the programming code. it's the entire .c file and everything in it that you wrote.

so if you want to describe it, then just write -- in plain words and simple sentences -- what your code actaully does. example:

the program prompts the user to input a number. it waits for the user to type a number and press enter, then it .... etc etc etc

how to run the program? that depends on how you present the program to your audience (ie your instructor)... since, i assume you are handing in the source code, they will have to compile it. so include compile instructions. here's an example if you use Linux/Unix machines:

copy the file "myprogram.c" to your local folder, then change directory to that folder and type the command: "gcc -o myprogram myprogram.c" ...

to describe the process of running the program, think what steps do you (or the user) have take to get the compiled program to actually start up.

thats it


.

jephthah 1,888 Posting Maven

why are you even using the type long? you know that long is an integer, right?

what you are doing here is taking the double floating point value (antal_minutter * minuttakst * 10000.0 + 0.5 ) , converting it into a long int which drops any fractional part, then converting it back to a double ... and then finally dividing by 10000.

get rid of the long type cast. that's what's hurting you here. Furthermore, since you've already defined everything as a double anyhow, you have no need to do any type casting at all. they already are doubles. this is all you need to do to get your answer:

beloeb = (antal_minutter * minuttakst * 10000.0 + 0.5) / 10000.0

also, you don't need to use the format specifier "%lf" to print a double. "%f" is the correct format specifier. actually i'm not even sure if "lf" means anything. theres an "Lf" format which only works on some compilers and means "long double" ... and that's an 80-bit floating point value, and I seriously doubt you need that, just for these little values.


.

jephthah 1,888 Posting Maven

^ i dont know how that fact informs the discussion here. It certainly doesnt change the fact that global variables/pointers are generally, if not always, evidence of sloppy programming.

perhaps sometimes, in some contexts, when sparingly used, they might be useful... but only when they are specified from the beginning and clearly limited to a specific and well-defined functionality.

but not as an afterthought, not as a quick-fix, and not because they are convenient.

jephthah 1,888 Posting Maven

ah cool. so did you get improvement in speed?

i see that your assignment was really more focused on the recursion... my code didnt even address that at all.

anyway, i just thought id post it, maybe it'll be of use somewhere. i got kind of obsessed about completing it :P

jephthah 1,888 Posting Maven

whoops. line 515 is wrong. it should be:

515. if (strncmp(argStr,"DEBUG",5)==0) .

jephthah 1,888 Posting Maven

really? you mean the CodeBlock IDE contains a GCC compiler on fresh installation?

well, damn, if that's the case, everyone please ignore my previous post.

:-O