jephthah 1,888 Posting Maven

Im still getting a bazillion compiler warnings and errors when i try and compile it on MSVC.

i changed the #include <dos.h> to <windows.h>, and changed your sleep() calls to Sleep(). that got rid of some of them, but brought in new ones to replace it.

did this compile for you even, on Borland?

and whether it did or didn't, you should really think about getting rid of Borland compiler, in favor of GCC or MSVC. borland was in the trash bin 10 years ago.

jephthah 1,888 Posting Maven

SALEM, he's actually getting better. his first 2 posts were "do this for me" without any code whatsoever.

now at least he's putting up some code.

FREDMAC:

what, exactly, do you expect this block of code to do?

printf(" Enter 5 to run the program or 6 to exit " );
scanf("%d%d", x1, x2 );

if ( x == 5);

and then once you've explained what you "expect" it to do, please tell me how you think it's going to do that.

and this is just your first problem. they get worse after this.

we can certainly sort through them all, but it's not going to be easy. you are missing some real fundamental concepts. and i suspect your semester is coming to an end soon.

by the way, this is not "C+" code. do you know which class you're in? you might want to seriously reconsider my final suggestion from your previous thread. it was serious.

.

jephthah 1,888 Posting Maven

question:

does each line of your data always have the same number of INTs and FLOATs, and are they always found in the same order?

if so, Dragon's suggestion for "sscanf()" is perfect. if not, you will need a more complex routine, perhaps using "strtok()"

jephthah 1,888 Posting Maven

another thing, "miles" needs to be initialized to zero before you start iteratively adding values into it.

just declaring it as a float does not initialize it.

Sh13 commented: Thanks for the help! +1
jephthah 1,888 Posting Maven

great.

now maybe for the sake of future searches, and as quid pro quo, you could briefly note what it was that you found wrong?

jephthah 1,888 Posting Maven

fscanf is problematic. you can easily shoot yourself in the foot with it.

if the file is not EXACTLY as you think it is supposed to be it will write garbage. it's very easy to use scanf wrong.

consider using fgets() instead of fscanf(). then you can choose from a variety of string.h functions (strcmp, strstr, strtok) to validate what the text file contains before trying to write it into your struct.

jephthah 1,888 Posting Maven

will/may pay cash.

lol

he wont get far on a job offers site with that verbiage.

jephthah 1,888 Posting Maven

okay, WTF is this? fseek( logger, ( NULL ) * sizeof( ADMISSION_DATA ), SEEK_SET ); NULL * sizeof(something) ?? zero times anything is still zero. if you just want the beginning of the file, why are you using fseek?

but a larger issue: NULL is a pointer. not an int. you cant multitply a pointer and an int. at least not on most compilers. Borland maybe you can get away with it, but not GCC. and probably not MSVC either.

jephthah 1,888 Posting Maven

welp, i just tried to compile your C code, and got a flood of compiler errors.

god forbid anyone try and run your code on a non-Windows environment.

for this reason you should stay away from CONIO.H and DOS.H...

but i imagine your entire class uses nothing but windows, and your instructor doesn't care if he teaches you programming without regard to the ugly consequences of using Non-ANSI C

anyhow, im on my way upstairs now, so maybe I'll peek at it on my vista laptop.

jephthah 1,888 Posting Maven

if you dont need to recall every individual grade, you can just add each grade for that person to a running total, and keep track of the number of entries.

then just divide the total by the number of entries for the average.

if you need to retain each grade for later use (display or further calculations) then arrays as salem ^ mentioned would probably be the bestest choice for you at this point.

jephthah 1,888 Posting Maven

you cant keep using strtok like that

the first use of strtok must call out the buffer as you did: my_ptr = strtok(buf,","); but each subsequent use of strtok on this file handle must use NULL instead of the buffer name. the buffer name is kept track internally. recalling it will screw it up. my_ptr = strtok(NULL, ","); see here: http://www.cplusplus.com/reference/clibrary/cstring/strtok.html

jephthah 1,888 Posting Maven

start here : http://www.math.uic.edu/~fields/DecodingGolayHTML/introduction.html or here : http://mathworld.wolfram.com/GolayCode.html

if you're an IEEE member (or become one) you can get all you ever wanted to know about extended golay encoders here: http://ieeexplore.ieee.org/Xplore/login.jsp?url=/iel1/2220/6409/00250332.pdf?temp=x

here, you can find a binary (23,12) encoder/decoder implemented in C : http://www.eccpage.com/golay23.c, add an overall parity check to make it (24,12)


.

jephthah 1,888 Posting Maven

Yahooooo!

:P

:(

jephthah 1,888 Posting Maven

First I have a question: Is there a mistake? Maybe an even number adds up to 3 primes summed up or even more?

a mistake where? in Goldbach's Conjecture? if you've found a mistake there, get ready for publication in the journals.

an even number can only be the sum of three primes, if one of those primes is the number 2. which isn't saying anything that the Conjecture isn't already saying. because if you subtract 2 from each side of the equation, you have the original conjecture: "even numbers greater than 2 can be expressed as the sum of two prime numbers"

and i suppose an even number (greater than 6) can be expressed by the sum of four primes because every even number greater than 6 can be expressed as the sum of two even numbers greater than 2.

which brings us back full circle, back to Mr. Goldbach.

the point is that (as far as anyone has ever calculated) ALL even numbers >2 are the sum of two prime numbers.

4 = 2 + 2
6 = 3 + 3
8 = 5 + 3
10 = 5 + 5 or 7 + 3
12 = 5 + 7
14 = 7 + 7 or 11 + 3
16 = 11 + 5 or 13 + 3
18 = 13 + 5 or 11 + 7
20 = 13 + 7
22 = …

jephthah 1,888 Posting Maven

Narue, think about it.... really. its a vending machine problem. CSC 101.

do you think his class is going to be expected to understand strtol pointers and how to use the "errno" library?? He's here because he cant figure out how to cast a char * string into an int.

can you even remember learning the basics how to program? you're an expert among professionals, girlfriend.

these people just want their programs to "work". they cant see the larger picture yet. thats why they're here.

im not saying though, that you shouldnt be giving the complex answers.... it is good, as the OP just stated, to see more options. I think its important that you're here to show them (and me!) the "correct" way to bulletproof code.

im just offering the simple answer for simple questions. for clarity.

jephthah 1,888 Posting Maven

hey i agree. i rarely use atoi, favoring strtol instead. and i always error check user inputs in my own code.

i am merely answering his simple question: "why doesnt X work?" with a simple answer: "because you can't use X like that... you must use Y instead."

now if you want to diverge into more advanced topics, and give him rope to hang himself... thats fine too. because if he tries to pass that code off in an assignment, and then gets called on to explain it -- and can't -- well, that's probably karma working like it should.

i mean, maybe he'll successfully study and understand what and why you're doing what you're doing, and learn some really valuable lessons. but, i think, just in my brief experience here with other similar posters, that is unlikely.

whatever. its all good. you're right, and you've already won. I'm scared of your chainsaw, okay? I'm just offering the answer at the same level of the question as it was posed. that's all.

jephthah 1,888 Posting Maven

Hi Ray

lets do this in a new thread, if you dont mind.

start a new thread and describe what you're trying to do and your attempt so far to do it.

you can post the link to the new thread in here, if you feel like it.

thanks

jephthah 1,888 Posting Maven

i'm totally down with everything you're saying. and, technically speaking, you're absolutely right.

i also see value in aia's approach.

MY point was that

(1) you can't do this: value=(int)argv[1]; (2) you must do this: value = atoi(argv[1]); (or similar, with strtol)

the poster obviously has a fundamental misunderstanding of how to get an int from command line argument.

now the place you're going with all your bulletproof errorchecking is just going to confuse the guy until he at least understands how to convert a char * to an int.

i dont think it's helpful to hand a beginner a fully fleshed out production-quality routine if they don't understand the basics.

i say let them send invalid args to the commandline and see what happens. otherwise they're just cutting and pasting your Beautiful Code without understanding what it really does.

jephthah 1,888 Posting Maven

never mind.

i dunno. too late to start

jephthah 1,888 Posting Maven

here's the simple answer:

int main (int argc, char *argv[])
{
    int value;

    value = atoi(argv[1]);

    ...

}

of course that doesn't even begin to address error checking. But that wasn't your question, so I'm leaving it that out in favor of the simple answer as to why your code didnt work (because you cant merely cast a string as an int)

now, lets the fight resume. i got 3:1 on narue. she wields a wicked chainsaw. i still have scars.


.

jephthah 1,888 Posting Maven

why would you want to use a hammer when you need a screwdriver?

jephthah 1,888 Posting Maven

i always hated it when i realized 3/4ths of the way through a semester i'd been sitting in the wrong class.

it did sort of make sense, in hindsight, as to why i thought everyone was talking moon-man talk.

jephthah 1,888 Posting Maven

okay... cut and paste this program:

http://www.engin.umd.umich.edu/CIS/course.des/cis400/c/hworld.html

then, add a couple lines: divide is done with the '/' operator and remainder (modulus) is done with the '%' operator.

another option (and one that may save you a lot of time) is to drop the class now, eat the GPA hit, and choose another major.

.

jephthah 1,888 Posting Maven

okay. on second thought... i'll help you:

(1) start with a main( ) function.
(2) #include some headers
(3) make heavy use of the "printf" function
(4) format modifiers. have some. they begin with "%"
(5) check out "fgets"
(6) '+' and '*' operators do math stuff. there are others, but don't worry about them now.
(7) learn to use braces. (the '{' and '}' thingies) ... you'll need them every so often.

and there you have it. please be sure to mark this question "solved" before you go.


.

jephthah 1,888 Posting Maven

what kind of outfit do you think this is? do you see a PayPal button somewhere that I missed?


.

jephthah 1,888 Posting Maven

glad we could help?

jephthah 1,888 Posting Maven

Dear Gerrit,

I just looked at the link posted by Chandrashekhar1.... let me save you some time.

What he posted is pure crap. It's largely incomprehensible, and likely rife with errors. don't waste your time downloading it.

go instead to any one of a number of credible and freely available tutorials/examples on C programming.

like this one, written by a professor at MIT, designed for the beginning programmer:

http://pdos.csail.mit.edu/6.828/2007/readings/pointers.pdf

or any of a hundred others.

jephthah 1,888 Posting Maven

definitely. stay away from any site that wants you to pay for "lectures" on something as universal as C programming

you can find tons of high quality and freely available tutorials and lectures from credible institutions and individuals all over the internet, without resorting to some dubious "institute of computer programming" who wants to sell you what is already available for free.

they probably are just repackaging someone elses material and selling it.

interestingly, this Chandrashekhar1 person has 2 posts, both of which are plugging this site he "came across"

EDIT

OMFG. i just downloaded his "introductory" free lecture, a zip of html files.. It's pure and total crap. i feel like i just violated my poor computer by putting such ugly and error-ridden garbage on it. i need to do a system restore and go take a shower.

jephthah 1,888 Posting Maven

glad you got it figured out :)

for Perl in Windows, i highly recommend that you use ActiveState Perl. It's the industry standard, and has a ton of modules and great community support.

http://www.activestate.com/solutions/perl/

they sell development kits, IDE's and whatnot, but the basic distribution is free (Active Perl)

jephthah 1,888 Posting Maven

I thought it was wrong, but I was wrong. it was late and i wasnt reading very carefully. sorry :)

those two functions that you're asking about, they seem to be okay. im sure someone will say it can be done better (someone always does) but I won't be that guy this time. :-D

as for the rest of your program, i think its a good first attempt at capturing the idea of the project. i like how you've tried to modularize all your functions.

thought there is still some room for improvements.

for one thing, your data gets erased every time you try a new operation. likely because your data is being declared and stored local to the add function rather than to main.

now you need to work out the bugginess in the interfacing between the functions. I'd start by declaring all of your inventory data in main() -- preferrably as a struct -- and then pass a pointer to that data into the functions that will modify it.

jephthah 1,888 Posting Maven

that's great site ^

i wish i would have known about that a few years ago

hell, i might just have to read it through tonight.

:P

jephthah 1,888 Posting Maven

global file pointers in a multithreaded environment? no wonder you've got problems. To repeat what i've been saying... this underscores the reason why you shouldnt use global file pointers. you can't keep track of them worth a damn, and god help the person who has to maintain your code a year or two from now.

globals, sparingly used, do have their place ... but they should not be used as a relief for poorly specified functions.

try spec'ing your functions more thoroughly and pass your file pointers as arguments.

jephthah 1,888 Posting Maven

you have an interrupt service routine of some sort.

when you get an interrupt, process the row that had the keypress event by calling the row function according to the particular interrupt. or call all four row functions in sequence if the interrupt is just generic to the keyboard and not row-specific. the return value of the row function will be the character pressed, if one was pressed, or will be an 'x' if no character was pressed on that row.

otherwise you would expect the first character pressed to be a number -- keep a running total of the first value to be used by storing the value of this number.

recall: if a nine is pressed, the value is 9. but if a three is pressed immediately afterward, the value of the previous nine becomes 90, and the three is 3, and combine for the value of 93 ...

if (when) the character input represents a math operation (addition, subtraction, etc.), hold the final total value of the previous number(s) pressed, and store the "fact" that you will be performing the requested math operation after the next value is finalized.

repeat the process for the next set of numerics, to get the second value.

once "E" is returned from the keyboard interrupt, process the final result in this manner

if (operation == 'A')
    result = value1 + value2;
else if (operation == 'B')
    result = value 1 - values2;
else if …
jephthah 1,888 Posting Maven

are you using <TAB> in front of each command? i cant tell since youre not using code-tags.

dont "simplify" it until you get it to work in the first place. go back to the beginning and adhere strictly to your dependency graph

________   ________   ________
| ND.C |   | PD.C |   | MD.C |
========   ========   ========  
    |____  ____|          |
        |  |              |
      __V__V__        ____V___
      | PD.H |        | MD.H |
      ========        ========
                          |
                      ____V___
                      | RD.H |
                      ========
wsn commented: Very helpful gave me a very good hint where I was lost thank you +3
jephthah 1,888 Posting Maven

i sure wish you'd use CODE tags, when you post code, please. it will help me to help you if i can read your code.

anyhow... check your line:

for(i=0,row=0;i<48;i++,row=row+10);

it has a semicolon after it. so

MPI_Send(&oldrow,s,MPI_INT,i,246,MPI_COMM_WORLD);

is only executed once.

there may be other problems, i dunno. but i expect that's a big one.

jephthah 1,888 Posting Maven

in general terms (although not exactly precise), the "socket descriptor" is used like the "handle" for the socket, similar to a FILE * handle. int sd = socket(AF_INET, SOCK_STREAM, 0); where "sd" is the socket descriptor and, like a file handle, is then used to make additional calls to the socket like "connect" "read" "write" and "close"

jephthah 1,888 Posting Maven

why are you trying to make your makefile?

the command should just be "make"... should it not?

jephthah 1,888 Posting Maven

here's your start:

int main (int argc, char *argv[])
{
    if (argc != 2)  // 
    {
        printf("usage: %s <filename>\n",argv[0]);
        return 1;
    }
    else 
        printf("your filename is <%s> ...\n",argv[1]);
    
    return 0;
}
jephthah 1,888 Posting Maven

If you don't start learning how to properly indent and use consistent spacing in your code:
1st you won't be able to see what you are doing.
2nd you are not going to make it.

3rd -- people here are going to get tired of looking at your posts and not bother to help you.

especially when it takes three times to tell you the same thing. i sure hope you take that fgets( ) prototype out before you post again.

jephthah 1,888 Posting Maven

you STILL are trying to define "fgets". fgets() is a standard library function, you do not need a prototype. that you're trying to do so, is at least part of your problem.

and do you REALLY want a character array ("buffer") to be 5 Megabytes in size??


.

jephthah 1,888 Posting Maven

okay on third thought.... im an arsehole, and there's nothing wrong with what you did.

and i'm gonna shut up now.

jephthah 1,888 Posting Maven

okay ... on second thought, my reply was unnecessarily terse.

you've got the basic idea about how pointers work, but you're missing some fundamental bits.

your functions arent that bad, really. just you cant go playing with pointer arithmetic like you're trying to do. you cant add integers to pointers to type doubles. if it works, its just because youre lucky.

jephthah 1,888 Posting Maven

if you don't know how to do RS232 in C, you definitely should not try USB.

here's a basic example

http://www.captain.at/howto-simple-serial-port-test-example.php

jephthah 1,888 Posting Maven

both of the functions you've posted are completely wrong and irretrievably broken.

throw them completely away, you can't even fix it.

re-read the chapter called "intro to pointers" or whatever.

jephthah 1,888 Posting Maven

thats a helluva mugshot

jephthah 1,888 Posting Maven

um sure, if you say so....

but i see you're still wielding a chainsaw.

:P

jephthah 1,888 Posting Maven

And what if string.h is not allowed to be used !!!!

so use pointers.

c`est la vie.

jephthah 1,888 Posting Maven

eek :icon_eek:


but yeah... i think i just answered a C pyramid question right here in this very forum, like 4 days ago.


.

jephthah 1,888 Posting Maven

i did test it, yes, and it worked.

a lot of your critiques were what the OP already had in there, and i didnt bother changing.

but you're right. theres some sloppy stuff. still, i say "sloppy working" is better than "sloppy not-working" which is what it was when i found it.

i've lost enthusiam i might have once had to try and make bulletproof and pretty code for these CSC 101 class assignments.

i'm also, sadly, not a member of the Beautiful Code Club :(

jephthah 1,888 Posting Maven

what did this have to do with C?

kpnprakash commented: yeh jephthah is correct +1
Salem commented: I was wondering that myself... +15