this assignment has never been given before!!!!11
jephthah 1,888 Posting Maven
Salem commented: "Who has time? But then if we never *take* time, how can we have time?" - Merovingian +29
this assignment has never been given before!!!!11
>>not true. MD5 is broken.
This is true that MD5 has been broken. I heard this news long before.
I'm happy to hear you are so well-informed.
so now there's no reason for you to continue promoting MD5 as an algorithm that produces unique hash values, yes?
OK, but it's just really difficult how to do it, a normal PC-user will never manage to break this algorithm
what a terribly fatal assumption! are you telling me a skript kiddie can't read a published algorithm and implement it on a $200 laptop?
"security through obscurity" is no security at all.
.
And if two files are different, their md5sum hash will of course be different.
not true. MD5 is broken.
in 2004, Wang et. al. demonstrated that forced MD5 collisions could be generated; in December 2008 the Chaos Communication Group forged an SSL certificate using forced MD5 collisions, in March 2009, Kilma published an algorithm that will force an MD5 collision using a single computer in less than one minute.
tell me what is the entire point of the book?
tell me, what is the entire point of this thread?
besides being a means for some random internet guy to air out his creepy obsession for a female user, while simultaneously demonstrating that he doesn't know anything about programming.
because anyone that would either (a) take the 20-year-old Unix Hater's Handbook as being some sort of serious critique in favor of Windows, or (b) use it as evidence that C++ is a "horrible language" .... that person is a gotdam fool.
looks like jbennet is scru's advocate, too.
it's a conspiracy, i say, a conspiracy.
what makes you think you know better than i do?
the very fact that you made this thread?
He finally got to you... Oh well
i know. i should be better than that. :(
aiight, dude. i'm tired of all this grabassery. here's standard c, that will actually work. I'm not going to bulletproof the input or conversion for you, but it's close enough for your needs, and better than what you had before:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char a[10];
int sum=0, count=0, min, max, val;
while(fgets(a,10,stdin)) // never use "gets()"
{
a[strcspn(a,"\n")]='\0'; //strip newline
if(strlen(a)==0) // dont loop input on feof() either
break;
val = atol(a); // standard library function
// and i hope to god you can finish this on your own
// ...
// ...
// ...
}
printf( "Min: %d, Max: %d, Avg: %4.2f\n", min, max, (float)sum/count);
return 0;
}
.
sorry, im just annoyed because i cant ever compile your code, and its taking forever for you to believe me.
it still doesnt compile with my standard GCC compiler.
you're not allowed to intially declare variables inside your for loops, for one thing. that only works in C++.
for another thing, int val = int(a[i])-48;
is illegal in C, as well.
and why are you STILL using gets()?? we've been over this already. now take that out and replace it with something sensible.
.
i actually worked at a place that used a Caesar Cipher to encrypt user passwords for the operators who ran the production equipment.
and the "encrypted" password file was stored locally on every production computer.
no joke.
my first day there, i was like.... "LOL, WUT?" :-O
i don't know why it doesnt compile for you.
let me ask you something: what compiler are you using?
.
not sure why the trailing NULLs are a problem. they probably existed in the memory before program startup, or were initialized in some manner during execution.
the first NULL after "2:00 pm" signals the end of the string. why do you care that there are more than one? anything after the first terminating NULL is not considered to be "extra data"
or am i missing something?
.
generally speaking:
int * myPointer;
int myValue;
...
myValue = *myPointer;
myValue now contains a copy of the value that is at the location currently pointed to by the pointer, myPointer.
is this what you're asking?
.
the string pointed to by checkSum will contain the numerical value of Total is expressed as a hexadecimal string due to the 'X' specifier. specifically, any letters (A-F) will be uppercase letters rather than lowercase due to the fact that the 'X' specifier is uppercase
furthermore the string will be at least four characters in width, and will be zero-padded if the resulting hex representation is less than four characters. this is due to the '04' in the format specifier.
in this specific example, the string of chars pointed to by checkSum will be 007B
and terminated by a NULL character \0
the memory location starting at the address of checkSum will be 0x30 0x30 0x37 0x42 0x00
.
it seems that his recent request for us to provide him a coded sorting algorithm is yet another stealth requirement being pushed in under the radar.
it's just an attempt to get us to do his work. slightly more sophisticated than the typical "dump my requirements and wander off" method most newly-joined members attempt.
but still, pretty obvious.
.
>gcc -o array array.c
array.c: In function `main':
array.c:16: error: 'for' loop initial declaration used outside C99 mode
array.c:18: error: syntax error before "int"
wrong, it does not compile at all. and then when i fix all your declarations, it still doesnt work. your input routine is broken. im trying to tell you why, but youre apparently not in a space to hear it.
so since you insist that your code is working just fine, with , i'll let you go ahead and finish it up.
be sure to tell your instructor that "all you have to do it on step debug or F10" and im sure they'll think it's groovy.
ehhh.... i'm tired of answering questions right now. I'm going to ask YOU some questions for a while:
Q1: run your program, enter 0x7F for one of your array entries. now tell me why is your program broken.
Q2: run your program, enter 100000 for one of your array entries. then tell me why your program shits the bed.
index, is exactly what it says it is: an "index". it indexes elements of the array. it's not an identifier, as it doesn't identify anything ... other than the index.
sure, you can use a sorting algorithm, and then your min and max will be at one end or the other.
until you start posting code and asking questions "the right way" i'm going to have to refer you to this site
having a physical delay helps demonstrate, but the delay should be significantly scaled: I'd say 1/10th. you dont want to sit at a real stoplight for 30 seconds every time you demonstrate/test the program :P
or try
$dir = "x:\\share1\\share2";
if (-d $dir);
{
print $dir," exists\n";
}
else
{
print $dir," not found\n";
}
.
yeah, that was really abrasive. sorry. :( i shouldn't take my issues out on people here. you were, after all, just giving him what he asked.
the problem is that the OP's approach itself is flawed. in a particularly bad way because it will work -- for a few weeks or a few months -- then stop working as soon as someone on the other end updates their webpage.
.
as an aside....
the plan to "reset bit 5" as a method to convert a string to uppercase will make for some fun times if the string ever contains a numeral or other non-alphabetical character.
It is indeed rather "cute".
:)
.
so you're hardcoding a solution that relies on some unaffiliated third-party website maintaining precisely the same formatting and whitespace of their webpages.
yeah....... i'm gonna have to go ahead and say that's a Bad Idea.
EDIT: no wait, on second thought, I'm gonna go ahead and say that's a F--KING STUPID IDEA.
nucleon quit coding shiite for this poor noob to shoot himself in the face with.
OP: do NOT attempt to parse a website based on the number of NEWLINES the source code contains.
DO parse a website based on the keyword or tag that marks the precise location where the text that you are searching for is located.
in other words: use fgets() to read each line, then for each line use strstr() to search for the location of the keyword or tag that marks what youre looking for.
furthermore, you dont even know if there's going to be a newline between the tag and the value you want, so you may actually have to look on the subsequent line(s)
if you dont know how to use strstr(), look it up, its in the <string.h> library.
.
i have had to debug 100K lines of production code littered with GLOBALS and GOTO statements, after it had been hacked to death by every stripe of self-taught jackleg programmer.
i do not pretend to lecture experienced developers using a few sparing GOTOs. Such as yourself: you are obviously a very experienced programmer who understands the concept of writing maintainable code. Even more than me.
But I have a serious aversion to any beginner asking how to code their "hello world!" program and using GOTOs and GLOBALS to do it.
GOTOS and GLOBALS taught at the beginner's level inevitably leads to years of shiite programming that eventually has to either be continually maintained at high cost of time and labor, or just tossed out and rewritten by someone else.
i, personally, am tired of being the" someone else" who seems to keep inheriting this crap.
"goto is teh EBIL!!!!!" crap is because a bunch of people were mindlessly following orders rather than thinking for themselves.
goto is teh ebil, because beginners mindlessly use it as a crutch to compensate for poorly-planned designs, and this perpetuates on into their professional work, where they cleverly develop a tangled mess of unreadable code that they only understand
then they finally realize that it's really crappy design, so they rationalize it as "job security" (with a wink wink nudge nudge),which is all funny and collegial, until they finally quit and leave the mess to be sorted out by someone else.
GOTO should be discouraged with extreme prejudice in any sort of forum that is dedicated to teaching beginners the basics of C language.
if an experienced programmer chooses to use a sparingly few well-positioned GOTOS in, for instance, some error handling routines of hardware drivers, then that's their business.
but beginners should be taught how to complete their pedantic CSC 101 programs using traditional C-language loop structures.
.
^ nice answer.
except one thing needs a bit stronger emphasis.
never, ever use "GOTO" this is not BASIC programming. You will be tarred and feathered.
(there may be an exception to the absolute ban on using GOTO, but that's not available until you reach Level 70.)
why would you care if the numerator is zero? are we no longer allowed to add or muliply zero?
it seems i missed the memo ... again.
:(
here is a snippet of code to start. it's not going to work by itself, and i'm not giving you any secret answers. at least i hope the formula to calculate the average is not a secret to you.
now you do the rest.
for (index = 0; index < NUMBER_OF_ELEMENTS; index++)
{
// calculate stuff with your array here
// ...
// ...
// ...
}
avg = sum / NUMBER_OF_ELEMENTS:
printf("minimum: %d, maximum: %d, average: %f\n",min,max,avg);
.
how do I get the maximum, minimum and the average of an array?
sum = 0
min = value of first array element
max = value of first array element
begin loop for each array element, index = 0 to (n-1)
--- increment sum by value of array element at index
--- if array element value is less than min, set min to this value
--- if array element value is more than max, set max to this value
increment index and repeat loop til last index is completed
average = sum / number of elements (n).
max and min will hold their correct values.
.
(1) this is C. not C++. check the forum and post appropriately.
(2) your code snippet doesn't even remotely begin to answer the question. obviously you didn't read the forum, but did you even read his question? did you even read the title of the thread?
(3) generally speaking we don't give away code for homework solutions, and we don't appreciate people who do.
getting alternately beat up then nursed by two daniweb gals?
where do i sign up?
:P
OMG... i forgot to initialize "i"
line 25: int i = 0;
and a more astute programmer than me reminded me that I ought to flush the output buffer. so also add for completeness:
line 28: fflush(stdout);
my programming muse also pointed out that my hardcoding the sizes in "fgets" and "strftime" is also a little weak, a preferred method would be to use sizeof(..
.
and that my use of 0x0D and 0x0A instead of '\n' and '\r' is also short-sighted.
le sigh.
.
you've "run the program" ? what program? i don't see any program.
and if you really want a suggestion, I suggest you throw Turbo C in the wastebin where it belongs. Use a real compiler that is actually used in industry. Microsoft's Visual C++ or the GNU GCC compiler.
when you call " DS1302GetAll (&systime);
", as Narue said, that function will fill all the elements of the "systime" structure with the individual time and date components.
then, in order to push this info to the LCD in a human-readable way, you need to format the elements in an organized, meaningful manner that the LCD output code understands it. that's what youre doing when you call the " sprintf(buf ...
" call; it formats this time & date info into the string "buf", so that your subsequent call to " lcd_puts()
" knows what to do.
one thing i'm uncertain about here, is your "printf()" command... you're programming a microcontroller, right? where exactly is this "printf()" command supposed to print it to? you shouldn't have a terminal. your output device is the LCD, and you've already sent the info to the LCD via the "lcd_puts()" function.
.
i'm confused.
are you taking a class in C++?
or C?
I'm partial to the use of "strftime()"
#include <time.h>
#include <stdio.h>
#include <string.h>
void timestamp_string (char * myString)
{
char timestamp[16];
time_t caltime;
struct tm * broketime;
// find current time, convert to broken-down time
time(&caltime);
broketime = localtime(&caltime);
// append timestamp in the format "_yymmdd_hhmmss"
strftime(timestamp,16,"_%y%m%d_%H%M%S",broketime);
strcat(myString,timestamp);
return;
}
int main()
{
char name[128];
int i;
printf("\nenter string: ");
fgets(name,100,stdin); // get string, strip newline
do {
if (name[i]==0x0D || name[i]==0x0A)
{
name[i] = 0;
break;
}
} while(name[++i] != 0x00);
timestamp_string(name);
printf("timestamped : %s\n", name);
return 0;
}
#
/* ... omitting irrelevant, working code here ... */
#
well, gonna be hard to tell whats going on, because that code is definitely not irrelevant, and i can't be sure if it's necessarily working.
specifically, i dont see what 'r' and 'c' are pointing to. is the memory being allocated? for all i know they could be uninitialized pointers. and what is 'verbose'?
I find it useful on occasion to place a prototype in a function.
for what reasons, and in what context?
please elaborate.
because you cant use variables to declare sizes of arrays. why do you feel that you need to dynamically size your arrays? what's wrong with hard coding them?
if you insist on dynamic memory allocation, then you need to use "malloc" . but i really suggest that you don't go there.
You're pathetic.
did i really piss in your cheerios, mate? is it so bad you're reduced to foaming about the mouth uttering unqualified personal attacks?
John A. rightly pointed out that a termios or ncurses solution would not be any better than your conio solution, just from the other direction.... and perhaps you missed it, but my attempt at self deprecating humor conceded the point. And your followup post about conditional compilation was right on the money, so it's obvious you "get it"
come on now, let's be friends, nucleon, you and me. we can go bowling or something :P
.
hmm. i thought my post was calm and to the point. the inappropriate use of and reliance on globals is a habit that is reinforced by laziness and/or a 'get-r-dun' attitude.
i understand your position: you think that at this point it's not worth the time to undo what he's already done. presumably, he'll learn to not learn globals some future point.
but what i'm saying is that I think it IS worth the time, right now -- otherwise, the time never gets taken. and the habit steadily becomes more firmly entrenched.
i'm just expressing my opinion based on my experience. i wasnt attacking you; don't take everything so personal.
.
At this stage I wouldn't bother de-globalizing your variables
when would you suggest he start "de-globalizing" his design process?
the inappropriate use of globals (ie 98% of the time) is one of the major systemic contributors to buggy, unmaintainable code.
remove those globals now and get the pain over with before it devlops into a chronic disability.
And you can write a termios.h solution that will be broken on every non-POSIX system. What's your point?
that my indignant self-righteousness only flows in one direction: from GNU/GPL and against MSFT.
it ain't right, but i can still sleep most nights.
conio.h
(if available to you) has the function_getch()
which is unbuffered and does not echo the character read.
i wish i could give you half a cookie, for your halfassed solution.
sure you can write a program with conio.h, but it will be broken on most every non-microsoft systems.
conio.h is a header file used in old MS-DOS compilers to create text user interfaces, however, it is not part of the C programming language, the C standard library, ISO C or required by POSIX. ... Most C compilers that target UNIX and Linux do not have this header and do not supply the concomitant library functions.
-- wikipedia
I have tried your solution but I can't solve it .(because i have no much more experience in C ). Please Can anyone write code?.. Thanks
we'll help you but you've got to show some effort. you cant just come here asking someone to do all your work for you.
surely you've written some code already? post it here, then we'll help.
if you havent written anything yet, you need to get busy. I'll give you a place start:
#include <stdio.h>
#include <string.h>
int main ()
{
//declare your variables first
//then write the body of your code
return 0;
}