jephthah 1,888 Posting Maven

"filled with errors" ??

step off my grill, dog. the code snippet -- as it is written -- *works* and it is entirely suitable for someone wanting code handed to them.

now tell me, do you always engage in such tendentious pedantry on trivial matters, or do you reserve this unappealing behavior only for the new people?

:roll:

jephthah 1,888 Posting Maven

Not quite, jephthah.

yes quite, Walt.

any industry C programmer will tell you to never use scanf, even for numbers, because if anyone puts a character in there, or any other invalid non-numeric...

the program *crashes*

as in, grinds to a screeching halt in the singlemost castastrophic event possible, and it's just begging to happen with a scanf()

now, if they want to use it in class, thats fine. but if the lesson is specifically about validating input then I dont know how anyone can reasonably begin to think that scanf() is a possible solution for a validation excercise.

I'm saying that scanf() is exactly what shouldn't be used in such an excercise, and i would expect that students will fail the test if they choose to use it in this specific case.

jephthah 1,888 Posting Maven

i think we are two trains passing each other in the night.

jephthah 1,888 Posting Maven

well I am new here .... but I didn't think the purpose of this site is to supply completely error-free and 100% syntactically-correct source code for people to cut-and-paste. thats what homework services do. im just giving ideas and a framework of code fragments on how to solve the problem.

anyhow, there's got to be some amount of effort and initiative to solve problems here. amirite?

jephthah 1,888 Posting Maven

As the OP hasn't responded

thats cause yall scared him away

jephthah 1,888 Posting Maven

yeah, you cant post 300 lines of code and expect people to sift through it. even if it didnt wrap across line breaks.

try parse out your specific questions, and make a simple example of what your main (or first) problem is. then work from there.

jephthah 1,888 Posting Maven

I guess you meant stdio.h .

oops, yeah. thanks

and i also meant to put the last "printf" statement *AFTER* the close of the while() block.

:P

jephthah 1,888 Posting Maven

you know what?

In my neighborhood of Seattle -- literally right in front of a taco join -- stands a 20 foot tall statue of Lenin. it is a master sculpture rescued from the Russian junkyards shortly after the fall of the Soviet Union.

do I care that he also was a murderer?

nope. because he's an important historical figure, and its really a cool statue, as a work of art.

anyhow, Bush the Younger is responsible for far more deaths of innocent women and children than Guevera could have ever imagined. At least Guevera killed his military enemies, regardless of how cowardly you want to paint him.

http://www.bridgeandtunnelclub.com/bigmap/outoftown/washington/seattle/fremont/09lenin.jpg

joshSCH commented: Justifying murder? Statues of lenin? You sure you an American? -2
jephthah 1,888 Posting Maven

the very basic basics of C file handling.

if ((fp = fopen(filename,"r"))==NULL) 
{
	printf("cannot open file `%s`\n",filename);
	exit (1);
}

while (fgets(buf,80,fp))   // this assumes text lines are less than 80 chars!
{
	if (strstr(buf,"waldo") != NULL) {
		printf("found him!");
		waldo++;	
	}
	printf("I found waldo on %d lines.\n",waldo);
}

fclose (fp);

this will get you started.

remember you always need to #include <fileio.h>

jephthah 1,888 Posting Maven

you have the right idea so far. your switch is (correctly) operating as conditional on the "paytype"

but why, within each case, are you trying to assign values to the "paytype" variable? each case should be asking for the type of payment that is appropriate for the pay type, and then calculating the weekly pay based on the repsonses and according to the paytype.

for instance, in "case 1:" you would prompt the user to input "yearly salary"... then simply divide that number by 52, and the answer is "weekly pay"

case 1:
printf("enter yearly salary in dollars: $");
scanf("%f",salary);
weeklypay = salary / 52.0;
break;

follow this patter with the rest of the cases (you might prompt for hourly rate, and number of hours ... or piece rate and number of pieces ... etc) then after you close the switch() statement, you can print what the worker receives. remember to format it in such a way that it looks sensible.

printf("this persons weekly check is $ %4.2f \n",weeklypay);

jephthah 1,888 Posting Maven

che guevera is a pop icon, symbolizing "revolution" for disaffected white middle class youth.

that is all.

so you can quit trying to attach some sinister meaning to it. His image is about as insidious as Andy Warhol's "Campbell Soup" or "Marilyn Monroe" artwork.

jephthah 1,888 Posting Maven

you get a goat

[IMG]http://media.funlol.com/content/img/vend-a-goat.jpg[/IMG]

but all i gots is some pocket lint.

jephthah 1,888 Posting Maven

hi, my name is Rob I live in Seattle and I'm an engineer for a large medical device company. I know enough C and a few other languages to get myself in trouble.

I found this site by accident (google search) and after reading a few posts, I thought I'd give it a try for a while. I got tired of the competitive BS, whining, and points-mongering at ExpertsExchange. This place seems better so far.

I havent used this handle (jephthah) in several years. since late 90's, I guess. one point if you recognize the name. I'd probably change it if I could to something else. is that possible? probably not.

jephthah 1,888 Posting Maven

Thanks for your valdiation sequence. It works but is a little overkill for my need this week. Out lessons have included validating integers

i dont know about your class' requirements or the understanding your teacher may have with you... but in industry its impossible to properly validate any function that uses "scanf". no one uses "scanf" because its so unreliable.

the problem with scanf, is if you enter an incorrect value, it will crash.

any program that crashes on a possible set of inputs, can not be validated; that is the whole point of validation, to not allow inputs that crash the program.

if I understand your intent, you rpove the float is positive by placing the input betwen a "range" of poitive integers ??

no, my example just checks for invalid characters. a basic float can have an optional + or - sign (but only in the first location), followed by any number of digits (up to length of string) and one optional decimal point somewhere in the string. a more robust example would strip whitespace and allow for exponential notation, but that's another issue.

anyhow, my point is that to properly validate a float, you must checks for letters and other non-numeric characters, more than one decimal point, or a + or - that is not at the beginning ... any of these items are invalid. try putting any of those into scanf and you have a program crash.

jephthah 1,888 Posting Maven

I work in a shop selling computer h/w and electronic kits/components and custmers regularly use

i'm sure they do ... but which manufacturers are "they", that you're talking about working "fine"?

i mean, certainly *all* the various manufacturers don't work fine. because I've had *some* that don't work worth a damn, or they only work intermittently. often these are off-brand devices some people buy cheap off the internet. not to mention that even the good ones can fail.

Now, I don't know about his particular brand off the top of my head. It probably is fine.

but before I go debugging any code, i'm going to verify the hardware works first. I already learned that lesson, the hard way. Because I'm slightly dense, I learned it a few times. :P

jephthah 1,888 Posting Maven

here's a bit more help, with the validation part, since my explanation is not real clear. this code is not complete. you'll have to declare variables, how to get the inputs, and determine what to do with the results (i just put vague "returns"), and such like that.

for (a=0; a<strlen(floatStr); a++) {
    if (a==0) {
        if (floatStr[0]=='+' || floatStr[0] == '-') ;

        else if (floatStr[0] == '.')
            foundDecimal = 1;

        else if (floatStr[0]<'0' || floatStr[0] > '9') {
            invalid = 1;
            break;
        }
    }
    else if (a>0) {
        if (!foundDecimal && floatStr[a] == '.') 
            foundDecimal = 1;

        else if (floatStr[a] < '0' || floatStr[0] > '9') {
            invalid=1;
            break;
        }
    }
}

if (invalid) {
    printf("you must enter a valid floating point number\n");
    return 0;
}
else {
    printf("the value: %f is valid\n", atof(floatStr));
    return 1;
}
jephthah 1,888 Posting Maven

i tend to avoid "do/while" loops. "do" statements are kind of unpopular with most c programmers unless theres a compelling reason to use them.

just use a while statement to get the same effect.

as for validating floats... stay away from scanf. I would personally input a string, validate that it only contains the type of characters desired (within the while loop), then convert it to a float using "atof" after you're certain the input is valid.

...

as for using MiracleC, it's probably okay for true beginners to learn on... meaning, for very simple programs. But like others mentioned, it's not exactly reputable... once you get used to the basics of C programming, do please get a worthwhile compiler.

Visual C++ Express edition is available free from Microsoft.. even if you're not a fan of the Redmond Software Giant, it is *free* and it's solid, and it's one of the industry standards.

the last thing you want to do as a student is try and debug some crappy compiler bugs :-)

jephthah 1,888 Posting Maven

connecting one serial cable to the other, and running two instances of HyperTerminal on the two different ports will verify whether or not it works correctly.

but the thing to remember is both of your com ports are acting as a DTE ... in order to communicate straight through, one has to be a DTE and one a DCE. the difference between DTE (data terminal emulator) and DCE (data communication equipment) is that the TX and RX pins are swapped (pins 2 and 3, on a DB-9)

therefore you need a "null modem" cable to communicate between two com ports on two DTE machines (ie, typical PCs). In other words, cross over your pins 2 and 3 and retry :-) here's a good reference

since you're not using handshaking, your task is much easier. if you can get both of the COM ports to communicate back and forth -- in each direction -- then the problem is not your USB-Serial converter. If it's not the hardware, and you're certain your code is correct, then I would think its a Windows application setting. Perhaps your API limits the default Com Ports to COM1 - COM4 ?

if you get a chance, try using TeraTerm. it's open source freeware, and highly configurable, and IMO much better application than HyperTerminal. I think you'll like it.

jephthah 1,888 Posting Maven

ive done a lot of work with COM ports, both real and virtual. Generally, I've not had problems accessing any of the com ports that are assigned by USB-RS232 converters. Ive gone all the way up to COM16 or maybe higher.

when ive had problems, its been for one of two reasons:

(1) the default Windows COM settings is preventing the use of any com ports numbers above a certain default number, typically "COM4"... there is a way to set this higher, pretty easy once you find it. Unfortunately my home computer is running Linux so I can't recall where this setting is found.

(2) sometimes USB - RS232 converters made by lower-end manufacturers have problems. especially with handshaking. If all else fails try a different manufacturer.

First what i would do is make sure you can talk through the USB-RS232 cable manually. Use TeraTerm or PuTTy or HyperTerm or whatever terminal emulator you like. Make sure that your converter cable actually works via COM5 in the emulator as the "real" port does on COM1 separate from your program. If it does work, and your program truly is apples-for-apples, then I would work on tracing down the problem i described above in (1).

good luck