jephthah 1,888 Posting Maven

somehow i doubt ditz could compile and run a program, even if you held his hand through every single step.

jephthah 1,888 Posting Maven

nice code.... a bit of pedantic tangent, perhaps, but i'll agree: my assumption of 8 bit chars was overly simplistic and may be incorrect for some environments.

still, the point was not to write bulletproof code, but to merely illustrate basic bit shift and mask techniques before getting into the structures of the winsock or sockets library

because i dont know anyone who would use the above method (my version or yours) to write a real network program. they'd use conditional compilation of the standard socket libraries that have been in use for 20-odd years.


.

jephthah 1,888 Posting Maven

Well someone started it and more than one have answered 'properly' so yes it seems it is relevant to someones interests.

hey look, if we're talking about who has a "crush" on cartoon character ( :icon_rolleyes: ) then it's totally appropriate to talk about sekksie fursuits.

and anyhow, if you want to keep score, more posts have been on furrys, than naruto. so furrys win.

jephthah 1,888 Posting Maven

i dont know what you did, but your code is not visible.

so, please use code tags.

jephthah 1,888 Posting Maven

okay, well before you get into the gory details of using winsock for network programming with C, you should understand the basic exercise of converting one number system to another number system, using bitwise operators.

consider the address:
10.1.10.127

if you convert each octet to a binary group

10         1        10       127
00001010  00000001  00001010  01111111

then the 32 bit binary number as one single integer has the decimal value.

1010000000010000101001111111(bin) = 167840383(dec)

you can programmatically convert between these number systems in either direction. consider (and understand) this snippet:

unsigned int  ipAddress = 167840383;
unsigned char octet[4]  = {0,0,0,0};

for (i=0; i<4; i++)
{
    octet[i] = ( ipAddress >> (i*8) ) & 0xFF;
}

now you have the four octets as unsigned chars in the "octet[]" array (char is just an 8-bit integer), and you can print them in the decimal dot format:

printf("%d.%d.%d.%d\n",octet[3],octet[2],octet[1],octet[0]);

.

jephthah 1,888 Posting Maven

well, in the spirit of full disclosure, i must admit i haven't used Visual C++ Express in a long time either.

I remember begin frustrated that the debugger didnt work and the installation conflicted with my MinGW compiler. ehh, for all i know the root issue may have been a variant of PEBCAK :D

Nick Evan commented: Some microsoft programs can actually grow on you ;) +19
jephthah 1,888 Posting Maven

even better, IMO, is Code::Blocks

because, unlike Visual C++, CodeBlocks is already a full-featured IDE and debugger from the start, and won't try to get you to buy an upgrade for $$.

jephthah 1,888 Posting Maven

well, that sure was a helluva lot of effort you put into "solving" someone's 5-year-old homework problem.

it almost pains me to tell you that it's completely broken and won't compile on any standard C compiler. :(

int main(void)
   {
      // in the future, code tags would also be nice

   return 0;
   }
jephthah 1,888 Posting Maven

depends on whether you use the winsock or sockets library.

see Beej's Guide for more info than you ever knew you needed.

jephthah 1,888 Posting Maven

^ i like that link.

i don't think there's an equation without using summation. i tried to think about it for a minute, but gave up. I'm not really a math guy. :D

jephthah 1,888 Posting Maven

give it up please do us all a favour. start a furry thread and stop hijacking this one k

because.... this one is just so relevant to anyone's interests?

ditz commented: Only comment that is irrelevant +0
jephthah 1,888 Posting Maven

Is there a tutorial around for how to post math terms?

it's just LaTeX markup tags. any reference will describe the basics

http://en.wikipedia.org/wiki/Math_markup

jephthah 1,888 Posting Maven

and you don't need a "Big Number Library". you dont even need a long int . 10,000 is easily represented by a regular integer

the way to approach this problem is by summation:

\sum_{j=1}^{\left \lfloor sqrt(n) \right \rfloor} \left \lfloor \frac {n}{j} - j + 1 \right \rfloor

note, the bars represent integer floor. in code it would look like:

int answer = 0;
for (j = 1; j <= ((int)sqrt(n)); j++)
   answer += (n/j - j + 1);

.

VernonDozier commented: Good formula and it looks nice with the TEX tags. +17
jephthah 1,888 Posting Maven

the formula posted by siddhant is fundamentally flawed. it only appeared to work, because it just happened to be valid for n=2 through n=8. as 'n' increases past 8, the result becomes more and more inaccurate.

n=9 to n=11, the result is off by 1
n=12 to n=14, the result is off by 2
n=15, the result is off by 3
n=16 to n=17, the result is off by 4
n=18 to ... the result is off by 5

etc

jephthah 1,888 Posting Maven

great googly moogly :-O

jephthah 1,888 Posting Maven

mrayoub:

%i and %d are equivalent. both of them specify the format for a signed decimal integer, and either are acceptable to use.

%u, as you have seen, is for unsigned decimal integer

however, if you have declared a variable of type int then you should not print it as %u, an unsigned int. That is a bad practice to get into... because while it may in many cases appear to work correctly, your integer may very well have a valid negative value , and the %u format will print an incorrect value.

if you want the variable to be unsigned, then make it unsigned by declaring it so: unsigned number; .

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

Hi,first i must say this is not my homework,because i am to young (14 Years old)to have programming homework.

that's ridiculous. 14 y.o. is High School, and you are certainly old enough to have homework in a programming class.

furthermore this is a typical standard homework problem.

i'm not saying that it is or isn't your assigned homework, but to say that it isn't because you're too young is just not credible.

jephthah 1,888 Posting Maven

Statistics on barking dogs

good lord, that's funny. but i don't think the OP is interested in buying a commercial product to submit as a school project or whatever he's trying to do this for.

a Do-It-Yourself project, i think you will need a sensor to detect sound (a microphone), a very cheap amplifier and bandpass filter circuit for 1kHz, and a microcontroller (such as PIC) to generate a serial output that could be read by the host computer.

probably an easier method may be to use the sound board on the computer with a microphone, but i've never tried that myself. perhaps someone else has...


.

jephthah 1,888 Posting Maven

neat

jephthah 1,888 Posting Maven

americans have better teeth and nicer tans.

we're also generally fatter.

jephthah 1,888 Posting Maven

a lot of parallels between Michael Jackson and Elvis Presley.

i wonder what will happen to the children.

jephthah 1,888 Posting Maven

everything is about the fur suit.

jephthah 1,888 Posting Maven

^ what he's saying is that you should *never* use the "equal to" comparison operator for floating point variables.

while his vocabulary wasn't precise about the type of comparison operator, he's correct that you should never use the "equal to" comparison operator to compare floating points.

instead use the greater than and less than comparisons (as you mentioned) to effect an equivalant comparison within a specified tolerance.


.

jephthah 1,888 Posting Maven

^ self-deprecating humor only works if there's a clear distinction between the person and the parody.

in other words: when a creepy internet stalker jokes about being a creepy internet stalker, it's not funny, it's just creepy.

Nick Evan commented: Haha :) +19
jephthah 1,888 Posting Maven

well... depends on the geek.

computer geeks would want their peanut butter ready-to-spread so they dont lose time omghaXing webpages or wtfpwning noobs.

on the other hand, "peanut butter geeks" would *want* the manual operation of having to reconstructed the separated peanut butter components. because they would be the "purists"

jephthah 1,888 Posting Maven

EDIT: never mind. find it yourself.

jephthah 1,888 Posting Maven

i don't think you can use the concept of 200 pages to measure time accurately.

but you can wait 3 1/2 years to respond to a thread and divide that time by the number of total posts, for a rough estimate of the number of thread-posts per year.

amirite?

Salem commented: That's the same as the number of pointless thread bumps per month :) +36
jephthah 1,888 Posting Maven

you don't have to initialize every member before the one you want to initialize. 0 is the default, so if I wanted to only initialize third, the old way is still the same but the new way is easier...

Wrong. Wrong. Wrong.

Structures, or any other variable, are not initialized to zero or any other value "by default" ... just because your compiler happens to do so, does not mean someone else's compiler does.

this error is probably the single-most source of broken code, and endless debugging efforts.

thanks for propagating crappy coding practice. :icon_rolleyes:


.

jephthah 1,888 Posting Maven

a camera will not natively store an image as a GIF. it will be a JPEG or a TIFF. all of these formats can be generically referred to as "binary".

your mission, if you choose to accept it, will be to understand the format (JPEG or TIFF) that your camera stores pictures as, and learn to decode it, before you can then manipulate it.

jephthah 1,888 Posting Maven

The problem is the way we are taught in school. In school, we still use
#include<iostream.h>,#include<conio.h>,getch(),clrscsr()...etc.etc....

I say that you should avoid the use of old, non-standard libraries like "conio.h" unless you are explicitly instructed -- required -- to do so.

anyone can quickly learn to use any library function that one may given in the course of their work. But you will only be hurting yourself if you learn to rely on those non-portable functions, and then one day find all your code is broken when you try to port it to another environment.

also, when you come to ask questions on a standard-C forum like this one or any of the other major forums, you will lose the assistance of people who do not, can not, or will not use non-portable libraries such as conio.

ultimately it's your choice. personally, my choice is that i just don't even bother trying to compile anyone's code who uses non-standard libraries. I simply don't care to include those libraries on my work or home machines, and therefore i don't spend any time trying to debug examples those people might post.

jephthah 1,888 Posting Maven

what is this, some kind of Furry bullshit?

jephthah 1,888 Posting Maven
iamthwee commented: *chuckles* +21
jephthah 1,888 Posting Maven

what salem said.

and, anyhow, if you really want to do this correctly, you will use the standard C library <time.h> ... you will make use of the time_t type, and the structure tm.


here is a tutorial

jephthah 1,888 Posting Maven

ahah

here's the OP, from one of his cross-posts:

hey there, do you accept payments to make me the code?

:D

jephthah 1,888 Posting Maven

no, its the way you ask for help

you whine and beg, but you don't ask a specific question. you just post a big slop of mixed up code and demand that someone fix it for you.

well, you need to start sorting through the compilation errors and fixing the obvious problems, then asking SPECIFIC questions about the rest of the problems that are still confusing you.

ask a SPECIFIC question, using normal language, like a normal adult and not a toddler. in other words, do not ask a question like:

>>somebody please help meeeeeeeeeeeeeeeeeeeeeeeeeee

that just is annoying and makes nobody want to help you. and anyhow, no one is going to just hand you code for your project. that's against the forum rules.

anyhow, your deadline is coming up quick. you should quit grabassing and get to work.

jephthah 1,888 Posting Maven

Hey jephthah, since when can we use single quotes for c-strings?

case 1: printf("\n%s\n", 'one'); break;
case 2: printf("\n%s\n", 'two'); break;
case 3: printf("\n%s\n", 'three'); break;
case 5: printf("\n%s\n", 'five'); break;
case 11: printf("\n%s\n", 'eleven'); break;

:P

oh, hell, i just cut and pasted his code. i didn't even notice that

:)

jephthah 1,888 Posting Maven

no,this is a C language program,i test it,this code is run,but don't work correctly,i don't know why work incorrectly!confused

no, this is C++. Not C. Which is probably a lot of your problem: you're confusing two related, but different, languages.

please help me ?
where i give my answer ?
if you can't answer me , please give me a slr parser project with c ?
i realy needed it,i must write a slr parser today
please help meeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

how sad.

you're not going to do well around here.

jephthah 1,888 Posting Maven

So far I have an A in the class

if that's all that's important to you, well, then congratulations.

of course, with an instructor who doesnt know a C compiler from a pile of horseshit, it's not anything to get real excited about.

but hey, whatever works for you.

jephthah 1,888 Posting Maven

um... you pretty much just described the two steps.

$  gcc file1.c main.c 
$ ./a.out

what more do you want to do?

Salem commented: Teach me to walk. "I put my right foot forward, then my left. Now what?" +35
jephthah 1,888 Posting Maven

the first one is classic thermodynamics.

im not sure about the second one, but apparently that's what this guy (OP) is doing.

jephthah 1,888 Posting Maven

i notice your function is called: "hanming" ...but i imagine you would easily figure out a compile time error such as that.

otherwise, i dont really have fooking clue as to what "calculating entropy of a file and coding it using hamming" means. To be honest, I was thinking of the Second Law of Thermodynamics and DSP Hamming Filters, so I was all like WTF??? :P

I did find your other posts here and here, to be of some interest.


.

jephthah 1,888 Posting Maven

as already stated, never try to use strings as cases for a switch. Some languages (like Perl) will allow this. C will not.

you could, for instance, try something like this:

void read_snum(char *sno)
{
   int courseNum;
   courseNum = atol(sno);
   
   switch(courseNum)
   { 
      case 1: printf("\n%s\n", 'one'); break;
      case 2: printf("\n%s\n", 'two'); break;
      case 3: printf("\n%s\n", 'three'); break;
      case 5: printf("\n%s\n", 'five'); break;
      case 11: printf("\n%s\n", 'eleven'); break;

      default: printf("\nInvalid Course Number\n");
   }
}

note, that my use of atol employs no error checking. I'm just using this as an example for switch/case statement. the preferred method would be strtol() and verify the string contains a valid number before moving to the switch.

.

jephthah 1,888 Posting Maven

Hello World!
i want to write a program

awesome!

Can any one help me!?

sure can!

Thanks in advance!

you're welcome!

.

WaltP commented: Was that necessary with the previous 3 responses? Useless posts like this do get old. -4
jephthah 1,888 Posting Maven

poast.

jephthah 1,888 Posting Maven

Gnutella (pronounced /nuːˈtɛlə/ with a silent g, but frequently /ɡnuːˈtɛlə/) is a file sharing network. In late 2007, it was the most popular file sharing network on the Internet with an estimated market share of more than 40%

...

The name is a portmanteau of GNU and Nutella: supposedly, Frankel and Pepper ate a lot of Nutella working on the original project...

http://en.wikipedia.org/wiki/Gnutella

:)

jephthah 1,888 Posting Maven

looks good.

still, you should get in the habit of

(1) defining declared variables
(2) declaring prototypes of functions.
(3) returning values from functions according to prototype.

otherwise a bunch of minor short terms gains that you get away with on your current compiler will, eventually, come back and bite you in the ass for some long term pain :)


Also, I really suggest that you learn how to use standard libraries, like <time.h>. the code snippet that Dave linked, above, is a concise and easy to understand example.

jephthah 1,888 Posting Maven

When I compiled this and added a few printf lines to help with the debugging before I asked for help, the leapyr function seemed to be working as planned. The problem was located somewhere else.

no actually the problem is there. and it's related to what i was talking about, 'local scope'

you have the variable 'leap' declared (but not defined) globally. there's no telling what this value may be

THEN you declare the variable 'leap' as an integer, local to the function "leapyr". this function calculates whether or not the year is a leap year (incorrectly, i might add... more on that later).

your print statement within "leapyr" prints out the value it calculates, and then attempts to return that value to the calling function (main)

however, "main" is not accepting the return value, as i mentioned previously, because you have no assignment. you probably think that the value "leap", defined globally, is modifed to whatever the "leapyr()" function changed it to.

But this is not the case.

because "leap" in the function "leapyr" is declared locally, it is modified local to the function's local runtime stack, only. the global variable "leap" is untouched. Like my analogy of the two "Joe Smiths" living 3000 miles away. here is the danger of using the same variable names, you confuse the programmer.

the quickest fix is to completely remove the "int leap;" declaration in your "leapyr" function, then it will use the global variable.

jephthah 1,888 Posting Maven

I understand that declaring leap in the main function and in the leapyr function are different, but that's why I declared leap globally

good lord, i really am not paying attention, am i?

i'm sorry.

let me re-look at this.

jephthah 1,888 Posting Maven

I've never dealt with the library functions in this program... I've only been programming in C for a couple days actually... So how can I figure out the functions in the library? Right now some of this is just gibberish to me.... Maybe it's just because I haven't had much experience yet though.

well, you're doing fine then. good job programming your day calculator "the hard way" :)

library functions are very powerful. essentially, they're just routines someone else has written to do some operation that is commonly used.

like "printf" is a library function (found in the <stdio.h> library) to print stuff to the terminal. <time.h> is another such library. learn the rules to use the functions in that library and life gets much easier.

look at Ancient Dragon's example above. it's probably a bit complex to you right now, but its easy to understand if you spend some time on it.

teh best way to learn is to use a debugger and "step through" the code one line at a time and watch the variables as they change values.