jephthah 1,888 Posting Maven

This isn't the place for "can you tell me about some feature of C". This is *not* a lecture hall, and we don't have the time to be unpaid tutors.

You have to remember, there are a *lot* of students who post here.

Post your code, and tell us your problem with it - we'll try to help. That's what we do, and that's about all that we have the time to do.

I'm sure you can google just about any subject or question to find tutorial material on the features of C.

damn, dude. lighten up already. this place isnt for you to vent your frustrations on some hapless student for asking legitimate questions. Yeah, perhaps he framed his question a little oddly (it did seem like he wanted code) but there is nothing wrong with asking questions on how C functions work.

because that's the purpose of this place: for students (and professionals) to ask C programming questions. Now if you dont have time to answer these questions, that's your business. don't answer them, okay?

but maybe you should spend more than a month here before you decide who this place is and isn't for.

.

Ancient Dragon commented: nicly put :) +34
jephthah 1,888 Posting Maven

i was being somewhat facetious. hence the :P face

but the fact remains:

these people are first year programming students -- if even that.

they can join the ACM forums later.


.

jephthah 1,888 Posting Maven

people who post questions here don't want long tutorials. they just want the answers

:P

jephthah 1,888 Posting Maven

ADAK is right, and i agree. But I also don't see a problem with giving brief, vague answers to brief, vague questions.

...

continue : stops execution within a repeatable block of code and immediately "continues" execution at the first line in the top of the block.

break : stops execution within a repeatable block of code, "breaks" out of the block, and immediately continues execution from the next line of code after the block

return : stops execution of code within a function and "returns" back to the calling function, continuing execution at the first line of code after the function was originally called.

....

if you want more explicit answers, you'll need to formulate more explicit questions.

as ADAK said, no one will write code for you here.

.

jephthah 1,888 Posting Maven

okay fine.

i've obviously missed something then, that you're doing somewhere, that gets rid of the extra byte.

good for you, im glad you got it working.

jephthah 1,888 Posting Maven

NEVER

EVER

USE TURBO C

it's worthless and using it will turn you into a crappy programmer .

jephthah 1,888 Posting Maven

last time Im going to post here:

it's IMPOSSIBLE for you to get the correct checksum if youve got the IP header spread over 21 bytes, like you do. it CANT be 20 bytes, if you've got the 4-bit "version" and the 4-bit "header length" spread across two chars.

i dont care if english is your second language... you can still COUNT, can't you??

so whatever your problem is, i don't know, but I'm done wasting time on this thread.

.

jephthah 1,888 Posting Maven

who knows? what little bit of code you posted makes no sense. you have no MAIN statement. i couldnt compile it if i wanted to. maybe if you post your code, we can see whats going on.


but if you want me to take a stab at it,

FIRST, i'd guess youre not callign your structure correctly.

assuming deck[] is an instantiation of DECK, so it only has two elements:

deck[].cards
deck[].atual

...

SECONDLY, *cards[52] looks wrong. you should lose the pointer, and just make it a 52 element array


.

jephthah 1,888 Posting Maven

thx, i'll remember that, but efficiency is not a "word" for me now.. :)

we seem to be having a major disconnect here, with comprehension or something.

i'm not talking about "efficiency". I'm taking about your code being "just plain wrong"

because that is what your checksum will be. wrong.

now if you don't care, then i don't care.

but the fact remains, you can't spread a 20 byte IP header across 21 physical bytes and expect the gotdam checksum calculation to work.

i havent even BEGUN to address "efficiency" .

get it?

jephthah 1,888 Posting Maven

show us what you've got

jephthah 1,888 Posting Maven

>i really wish threads that have been inactive for
>more than 90 days would be automatically locked.

I don't. It's a good idea in theory, but painfully annoying in practice. Besides, there's no rule against adding to an existing discussion, regardless of how old it is.

the only thing painfully annoying, is reading a page of discussion, writing a reply, and then realizing its some 3-year-old thread from an OP who is long-gone, that was reactivated by some stupid noob.

because most every other legitimate forum on the internets has an "expiration" feature, i'm not in the habit of inspecting "post dates" of every thread.

theres nothing that needs to be added to some year-old thread that's of any importance.

jephthah 1,888 Posting Maven

thanks for the replies.

one word of caution. just because it calculates a checksum, doesnt mean the checksum is correct. you still have 21 bytes. the fact that you think you're only using 4 bits for HEADLEN and VERSION, doesnt change teh fact that they are each chars and occupying 8 bits of memory space

jephthah 1,888 Posting Maven

in <math.h>

"log" is the natural logarithm (base e)

"log10" is the base10 logarithm


.

jephthah 1,888 Posting Maven

If all he wants to do is calculate someone's age it doesn't really matter that the Gregorian calendar wasn't invented until the 16th century

true, and i said as much in my last post.

but it doesnt change the fact that, for several reasons, the premise is flawed

:)

jephthah 1,888 Posting Maven

i just can't imagine it being really THAT hard of a feature to implement.

jephthah 1,888 Posting Maven

^ wasnt tongue-in-cheek, although you might say it was tangential :P

just pointing out there are some difficult issues reconciling the different calendar systems if you try and go back two millenia. ...

however you can do this exercise exactly as Ancient Dragon said, and you will get a correct answer even though the premise is flawed... the absolute # days past this arbitrary (and imaginary) "year 0" will be wrong, but the "delta" in number of days between a persons relative birth-day and relative current-day will be correct. (assuming they weren't born in 1900 or earlier...)

it just seems to make more sense to start from a baseline of the year 1900 instead of the imaginary year 0 because then you're not switching between entire calendar systems.

or, as Vernon noted, just learn how to use the struct_tm functions, since this is what they were designed to do.

jephthah 1,888 Posting Maven

there was no "year 0". what we now call 1 BC was followed directly by what we now call 1 AD. (or 1 BCE followed by 1 CE, if you prefer)

When the Gregorian Calendar was adopted, they "threw out" 10 days to realign the calendar with the sun.

and changed leap years so they do not cycle once every 4 years. they skip years divisible by 100, excepting those also divisible by 400. 1900 was not a leap year. neither was 1800 or 1700. but 2000 was.

there are other problems reconciling the Julian calander, which was lunisolar, with the current Gregorian.

in any event, you're not going to have an accurate count of the number of days over the past 2 millenia.

jephthah 1,888 Posting Maven

TRIAD, sorry for the delay... for some reason, i dont get email notification of responses to threads lately, there's been a lag somewhere.

DWKS, there are no "backs" to go behind, mate. that's why we keep this all in the open. everyone is welcome to contribute. :)

Still, the first problem is his structure is NOT 20 bytes. it's 21. (regardless of what the comment says it is :P ) ...

That's why I'm saying he has alignment issues. "Version" and "HeaderLength" are only 4 bits each, and they need to be concatenated together into one 8-bit char.

if he gets the entire header correctly aligned into a string of 20 bytes, then a method like the one you described will work, and is what i've been trying to tell him do do all along :D

but i dont understand what do you mean by split the "DESTINATION and SOURCE IP ADDRESSES

the IP addresses are 4 bytes each.

in order to caluclate an IP checksum, you need to calculate all values by "performing 1's complement addition on the header broken into ten (10) 2-byte words"

so you split each of the addresses in an "upper half" and a "lower half", each sized 2-bytes.

you can do it like the way DWKS showed you. another way that might be easier to understand is convert the code you posted earlier, to convert your struct into an array of unsigned shorts, like so:

IP_HEADER …
jephthah 1,888 Posting Maven

"IP Header Version" can't be more than 4 bits. that's not allowed.

i think you need to study up on IP

read RFC 791. pay special attention to Section 3: Specification

http://www.faqs.org/rfcs/rfc791.html

here's another summary:

http://www.networksorcery.com/enp/protocol/ip.htm

.

jephthah 1,888 Posting Maven

damn. i typed out a huge reply, and just lost it. sorry, but i just can't retype all of that... :(


(1) you need to use shift operators and bitwise-ANDS

(2) no, you cant do that. you need to do something similar to the code you posted that uses "memcopy"

jephthah 1,888 Posting Maven

yeah, i really wish threads that have been inactive for more than 90 days would be automatically locked.

jephthah 1,888 Posting Maven

TRIAD

the code you show is how they perform 1's complement addition to calculate checksums.

its more complicated implementation of the basic process that I outlined to you above.

...

the last bit of code is a conversion of data from a structure into a string of unsigned chars.

so, yes, you could do something like that to convert your structure into a string of shorts.

be forewarned, though, your problems still exist with your arrangement of header elements, particularly VERSION and HEADER LENGTH should be concatenated into one 8 bit char, not strung across two.

seriously, i reccomend that you try to implement the basic IP header checksum process i described rather than blindly trying to apply some code from the internets that you don't understand.

jephthah 1,888 Posting Maven

I hate it when people use acronyms that I don't know the meaning of.

for real, man... me too!


by the way, have you met "TRIAD" ?

he's the original poster

:P

jephthah 1,888 Posting Maven

never mind.

jephthah 1,888 Posting Maven

ramyavairamani's solution is correct, although not entirely complete as stephen84s showed.

all you have to do to avoid the overflow, is by first checking if either "a" or "b" is negative. if one is negative and one is not, simply return the one that is positive as the greater value

if both are negative, or if both are positive, then ((a-b) & MIN_INT_VALUE) will indicate which one is greater, as previously demonstrated, and without the danger of overflow.

.

jephthah 1,888 Posting Maven

where is "MODEL" defined?

jephthah 1,888 Posting Maven

ah, that would explain the lag.

which forum is that?

jephthah 1,888 Posting Maven

I dont think you're going to use sscanf very easily on strings that can be wildly divergent from any imaginable standard format.


.

jephthah 1,888 Posting Maven

TRIAD,

your question should be "how do i calculate a checksum" .... NOT "how do i convert a struct to a short".

the quick answer, is that you take your entire header and divide it into 2-byte "words", along their natural 16-bit boundaries, and perform a 1's complement addition on each word for a total checksum that is itself a 2-byte "word"

but before you do that, you've got a few potential problems, in that your header values do not align on the 16-bit boundaries.

your first two CHARs should not be individual 8-bit values, but should be concatenated into one total 8-bit value where VERSION is the 4 MSB's and HEADER LENGTH is the 4 LSB's. -- then that 8-bit value is itself concatenated with the TOS, where VERSION/HEADER are the 8 MSBs and the TOS is the 8 LSBs.

now you have your first "word"

LENGTH, ID, and OFFSET are your next three "words"... but it is important to note here that the first three (3) MSB's of the OFFSET are actually flag bits. (you may already know this and be handling it properly, but its not obvious from your structure.)

TTL and PROTOCOL are concatenated into the fifth "word", where TTL is the 8 MSB's and PROTOCOL is the 8 LSB's.

the HEADER CHECKSUM field will eventaully be the sixth "word" --- but for purposes of calculating this checksum in the first place, you ignore this field at …

jephthah 1,888 Posting Maven

you can't use any of the relational operators?

>, >=, <, <=, ==, and !=

well, then, what do you have left that could possibly be of use?

bitwise and logical operators.

jephthah 1,888 Posting Maven

you posted this question twice dave.

does your program not work?

what is your question?

jephthah 1,888 Posting Maven

well, does your code work like you expect it to?

jephthah 1,888 Posting Maven

how u wil separate sentence if there is
exclamation mark in it..
a sentence may or may not end with exclamation mark..

i gave you the answer.

the answer is STRTOK

if you dont want that answer, then you're more than welcome to go roll your own version of a string tokenizer.

jephthah 1,888 Posting Maven

Maybe it's wise I don't use atoi

bingo.

next question: what is the point of all this? is it your entry into a Goldberg Machine contest?

jephthah 1,888 Posting Maven

remember this fact:

a variable of type char is just an 8-bit int.

thats all it is, and all it ever was.

try this and see: int a = 65; printf("%c", a);

jephthah 1,888 Posting Maven

your example is wrong, according to your own definition. if you want to separate sentences, then you need to also break on the exclamation point

[b][u]output:[/b][/u]
        Hello! 
        This is MAYANK.
        I am a Student of "nitk."
        Working on a project.

anyhow... time to repeat my earlier advice:

the function that would be helpful for you here, i think, is STRTOK

in the string.h library.

it will separate any text into "tokens" based on a set of "delimiters"

your "tokens" will be the individual sentences, and your set of "delimiters" will be the set of all sentence-ending punctuation.

once you have your individual lines you can do what you want with them ... such as insert newlines between them and rewrite them to another text file

http://www.cplusplus.com/reference/c...ng/strtok.html

CAVEAT: you will need extra logic -- in addition to the STRTOK -- to handle the event of end-of-sentence punctuation found inside a quotation mark.


.

jephthah 1,888 Posting Maven

oh, dur.

you're right.

brainfart.

jephthah 1,888 Posting Maven

the function that would be helpful for you here, i think, is STRTOK

in the string.h library.

it will separate any text into "tokens" based on a set of "delimiters"

your "tokens" will be individual lines, and your set of "delimiters" will simply be the newline character '\n'

once you have your individual lines you can insert anything you want in between them, and then rewrite them to a buffer or another text file as you desire.

http://www.cplusplus.com/reference/clibrary/cstring/strtok.html

jephthah 1,888 Posting Maven

hmm. that's interesting to know...

so Stephen84s was not incorrect after all... at least as much as the answers are compiler-dependent.

now i feel like a turd for giving him a rotten cookie. someone should give him a green.

or me a red.

or both.

.

jephthah 1,888 Posting Maven

Hi, it's me again...
I've some problems understanding why my program hang up

what do you mean, its not running? the code as you posted works. do you mean that if you have the first line in "void foo" by itself it works, but the other line (by itself) doesnt? well, that's true, then.

but both lines together in "void foo" work as you would expect.

here's what's happening:

in "main", you declare a pointer to an undefined region of memory, and you call it "bar", and you further declare that all elements starting at that location will be of type "char". in other words, "bar" is a variable of type "char pointer" that contains an address to a location of as-yet-undefined memory space that is expected to hold character elements.

then you pass the address of that pointer to the function "foo"... it expects a pointer to a pointer, so it's happy

from "foo"'s point of view, it gets a pointer to a pointer to a location of memory that is type char. in other words, a pointer to an array of chars.

you then define that location to contain the string of chars "foobar" and because it's so nice, it tacks a NULL character at the end of the string for you.

you then define the first element of the array of chars now contain the single character 'b'. the program doesn't care, but it just so happens to overwrite …

jephthah 1,888 Posting Maven

When you declare a "char" array as char *abc="alpha" , the string is not editable i.e. readonly, You need to declare it as char abc[]="alpha"; , if you wish to edit by using the abc[index]=''; method,

Why this difference exists however I am not aware of !!

well, y'see... hmmm... okay, i guess i don't really know WTF you're talking about

because to declare an array of chars as either char * myString or a char myString[] is the same effect. in either case, "myString" is a pointer to the address containing the first character of that array of chars.


.

ssharish2005 commented: Well said!! - ssharish +2
jephthah 1,888 Posting Maven

OKAY, Nelledogg,

I apologize for derailing your thread. I'm also sorry for accusing you of not writing the code you posted. It did look kind of odd that you posted all this very nice code with lots of functionality, but there were yet so many compile errors.

i can see, however, that if you had left it for a long time, that you could easily have forgotten what you originally did.

so, lets start over... and get this working for you.

Here is what I have done. I have fixed your code, just enough to make it compile. it does not even come close to doing what you need it to do, there is still a lot of work left that YOU will have to do. but i'll help, and I'm sure many others here will as well.

Inspect what i have done, along with the comments, so you can understand WHY i did what ive done. you'll see that your framework code now compiles and executes with a minimum of functionality.

again, sorry for all the stress.

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

#define COMPANY  "Rocklin Realty"
#define TRUE     1
#define FALSE    0      // FORGOT TO DEFINE --jephthah
#define TAB      25

void setagents(double *a, int c);
void total_sales(double *m, char **cal, int c);
void agent_sales(double *m, char **cal, int c);
void valid_date(char *date, int min_yr, int max_yr);
void titles(void);
int headings(void);
int menu(void);
void add(void);
int quit(void);
void message(char *msg); …
jephthah 1,888 Posting Maven

if youre trying to connect to a URL via sockets, the IP and port you need to bind to is the URL itself, not the proxy through which you connect to the URL

jephthah 1,888 Posting Maven

hi,
the first thing i noticed is there's no total_sales function, if u can c the total_sales just lemme know, so i wonder how case 2 gonna work, n just @ a 1st sight, there r more prototypes than the cases, maybe if u send us ur source we might help u figuring out whats wrong whith that, plus it will make us a gd exercice,
right guys?

not really.

how about you NOT talk like a 12-year-old texting message to your friends during recess, mmkay?

.

iamthwee commented: how about you NOT talk like a 12-year-old texting message to your friends during recess, mmkay? -This sentence does not make grammatical sense. -3
Salem commented: Works for me! +17
jephthah 1,888 Posting Maven

two out of three ain't bad

jephthah 1,888 Posting Maven

nelledogg,

i just gave you postive comment because i thought you wrote that nice code yourself. you said "here is the code i have written"

but then you obviously dont even know how to pass arguments into a simple function, as evidenced by your attempt case 2: total_sales(double *m, char **cal, int c); so you DIDNT write any of this code, did you?

because the rest of your code is using far more advanced concepts than passing simple arguments to a function.

now why don't you tell the truth about what's going on here?

jephthah 1,888 Posting Maven

LOL

but seriously, if there ever was a problem that should be solved by Perl... this is it.

look into Perl. this is the kind of problem it's designed to do. and can do it in about 3 lines of code.

jephthah 1,888 Posting Maven

dont have to be sorry.

it was an easy mistake to make. AVRs are an Atmel product.

jephthah 1,888 Posting Maven

Doing so with characters is your best bet unless you're using Windows API and you're forming an application.

this doesnt make any sense. what's any of this got to do with Windows API?

you've got an 8x8 matrix of single characters... what meaningful information can you have in such a thing?

you should make an 8x8 matrix of a structure that describes every important aspect of any board position.

jephthah 1,888 Posting Maven

a char will hold a single character, which is just an 8-bit int.

what information are you trying to contain in any 'square'?

this doesnt seem very meaningful, to have one char value in any square...