jephthah 1,888 Posting Maven

i try to avoid fscanf() because this function requires the input to be very precisely defined, and will cause you much headaches if your input (i.e., the files) ever vary from what you expect them to contain

use instead "fgets" to read each line, and something like "strstr" or similar to parse the result

jephthah 1,888 Posting Maven

well.... maybe it's a pedantic exercise assigned by his professor?

jephthah 1,888 Posting Maven

^ BEEJ's is a classic guide. read that, and you'll learn everything you need. try the examples, and come back if you get stuck.

jephthah 1,888 Posting Maven

timestamp your logs by date (or week, month, etc.) then you can delete the old ones at your leisure.

you can keep the most current log name without a timestamp if you like, then before creating a new one the next day (or week, month, etc.) just rename it.

jephthah 1,888 Posting Maven

your function is very nice, but i have to ask, what's wrong with

memset(string,0,21);
jephthah 1,888 Posting Maven

--------------------------------------------------------------------------------------

Hello,

really, I only want a transmisor/receiver system. In C or C++ or nestC or others.

thanks

wait... you want someone to write your code for you so you can get your degree?

yeah, let me ge right on that for you.

what school do you go to, by the way?

jephthah 1,888 Posting Maven

LightSystem adiciona-me no MSN, preciso de falar contigo e preciso de uma ajuda.. <email removed>

engrish, por favor.

and dont post your email address

jephthah 1,888 Posting Maven

Dear Achmat

sorry for crapping in your thread. since it was over a month old when i first saw it, i figured you were long gone. if you're still around, let me know and i'll try to help you with it.

it would help if you can provide example files such as the ones you're trying to use


.

jephthah 1,888 Posting Maven

yeah, actually, it is pretty doggone clean code, esp. for Perl... I dont remember it being like that. did it get cleaned up? guess not, i dont see evidence of an edit...

Really, I did read "strangling newbies" in my dyslexia and found it amusing... too bad my comment wasn't nearly as cute.

i guess since it was already over a month old, with no replies, i figured it was a dead thread.

sorry.


(and really, im not "angry" ... im just a run-of-the-mill internet a--hole :( )

.

jephthah 1,888 Posting Maven

i guess i wasnt thinking of the people like you who answer questions...

i was thinking of the hordes of people who pop in and say "ne1 plz to do 4 me the homeworks ok thx u"


.

jephthah 1,888 Posting Maven

i dont understand your question.

you want to send the number of seconds?

well.... the number of seconds of "what"?

jephthah 1,888 Posting Maven

meanie :(


lol :D

jephthah 1,888 Posting Maven

OH ... Wait, are you trying to compile this as a C++ program? this is not a C++ program. what you have here is a basic "C" program.

thats your first problem. you need to figure out what language your programming in.

as to your "real" problem... you are getting the input (mostly) correct, but you are not adding the coefficients of similar degrees together.

in other words, your single function "add" is doing everything BUT adding.

another problem appears that you should have THREE (3) polynomials, not two. hence the "add" function has three inputs (f, g, h) and one output (the sum of the three). each of these are arrays of a size that depends on the degree of the polynomials.

it would help if you wrote your "add" function to actually add the coefficients that you should have already gotten from your "main" routine, and passed TO it.

so before going any further, stop now, and rewrite your program to make sense according to this pattern:

SIMPLE PROGRAM FLOW EXAMPLE

"main"  -- gets the input from user as to how many degrees
        -- get each of the coefficients for all three polynomials.
        -- pass this info into the function "add"

"add"   -- add the same-degree coefficients together of each polynomial
        -- return the results back to "main"

"main"  -- format and print the results

dont worry if it doesnt work exactly right, just get it in this form. then, at …

jephthah 1,888 Posting Maven

you're not running the same program i am, apparently.

im running the code you pasted above. it compiles and runs without issue.

im using MSVC also. perhaps you are running something different than what you posted.

jephthah 1,888 Posting Maven

bah.

extra credit if you fix my bug

:P

jephthah 1,888 Posting Maven

check this out. compile it and run it and see how it works.

the function "stripCharacters" will strip out any undesired characters using the standard library function strtok... very powerful function, learn to use it.

#include <stdio.h>
#include <string.h>
#define MAXLEN    32

//////////////////////////////////////////////////////
//
// function : stripCharacters
// 
// input  : character string to be modified
// output : the modified string (original is lost!!)
// return : number of chars stripped, or -1 if error
//
//////////////////////////////////////////////////////
int stripCharacters(char * user_str)
{
   char copy_str[MAXLEN], *ptr;
   const char CHARS_TO_STRIP[10] = ",$%#";
   
   //error check, make sure string is not too long
   int stringlen = strlen(user_str);
   if (stringlen > MAXLEN)
       return -1;

   //make copy of user string, modified version will replace it
   strncpy (copy_str,user_str,MAXLEN);
   
   //look for first instance of "strip characters"
   ptr = strtok(copy_str, CHARS_TO_STRIP);
   strcpy(user_str,ptr);

   //look for additional strip characters
   while(ptr)
   {
      ptr = strtok(NULL, CHARS_TO_STRIP);
      if (ptr)
         strcat(user_str,ptr);
   }
   
   //modified string is passed back in original string variable
   //return value indicates number of chars stripped, if any
   return (stringlen - strlen(user_str));
}



int main()
{
   char myString[32];
   int retVal;

   strcpy(myString,"1,234,567,890,123");
   printf("original:  %s\n",myString);
   retVal = stripCharacters(myString);
   printf("modified:  %s   (stripped %i)\n\n",myString,retVal);

   strcpy(myString,"$5,299.99");
   printf("original:  %s\n",myString);
   retVal = stripCharacters(myString);
   printf("modified:  %s   (stripped %i)\n\n",myString,retVal);

   strcpy(myString,"0.039%");
   printf("original:  %s\n",myString);
   retVal = stripCharacters(myString);
   printf("modified:  %s   (stripped %i)\n\n",myString,retVal);

   strcpy(myString,"#103");
   printf("original:  %s\n",myString);
   retVal = stripCharacters(myString);
   printf("modified:  %s   (stripped %i)\n\n",myString,retVal);

   strcpy(myString,"999888777");
   printf("original:  %s\n",myString);
   retVal = stripCharacters(myString);
   printf("modified:  %s   (stripped %i)\n\n",myString,retVal);

   strcpy(myString,"123,456,789,012,345,678,901,234,567,890");
   printf("original:  %s\n",myString);
   retVal = stripCharacters(myString);
   printf("modified:  %s   (stripped %i)\n\n",myString,retVal);


   return 0;
}

.

jephthah 1,888 Posting Maven

every time i see this title Making War in the list, i think of that segment from the movie "Clerks" ... you know, the Russian metal head dude who sings his "Berserker" song for Dante's girlfriend after Jay and Silent Bob encourage him:

My love for you is like a truck, Berserker
Would you like some making f--k, Berserker

i suppose 90% of the folks here won't get this reference.

oh well :P


.

jephthah 1,888 Posting Maven

what's a "false signature"?

jephthah 1,888 Posting Maven

it looks to me like you're supposed to create a header file according to a specific format (partially described above) based on attributes of the binary or hex file in question.

is that right?

jephthah 1,888 Posting Maven

in the future, dont make duplicate threads for the same problem. please go and close your other thread with the same title.


I'm using the free MSVC compiler, and im not getting any runtime errors... it compiled and ran without any issues.

of course it is incomplete and does not give the right answer, but theres nothing wrong "compile wise"

what compiler and OS are you using?

jephthah 1,888 Posting Maven

nice summary.

but are you trying to drum up business for your website? you wont find it here.

all you'll find here are students from second-world countries trying to plagiarize their way through tech school.

jephthah 1,888 Posting Maven

sure, sure. i've got nothing better to do than do your homework.

shall i also write your report, bind it, and mail it first class to your instructor?

jephthah 1,888 Posting Maven

I think what the OP is trying to get at is that the input text, AND the query are both free-form user input.

that's what i gave him, at least the interesting bits. my example "$word" can be any string. i did not spend time on how he gets input into the variable.

Crafting specific RE's to deal with the example text and "RNA binding protein", whilst interesting, does not solve the problem.

well, i don't find that to be interesting at all.

and it's not what i did.

jephthah 1,888 Posting Maven

i already gave you the answer. i'll repost it using your variable names:

# variable "$word" is set by user search request
# variable "$sentence" has text to be searched

$word = "rna binding protein"     # ---OR---
$word = "rna-binding protein"

@matchwords = split(/[ -]/,$word);

$newmatch = join("[ -]",@matchwords);

if ($sentences =~ /$newmatch/i ) {

      # do something

}
jephthah 1,888 Posting Maven

me too.

jephthah 1,888 Posting Maven

i would personally do something like this:

$match = "rna binding protein"

@matchwords = split(/[ -]/,$match);

$newmatch = join("[ -]",@matchwords);

if ($_ =~ /$newmatch/i ) {

blah blah blah

}

jephthah 1,888 Posting Maven

"perltoot"

jephthah 1,888 Posting Maven

the answer is "yes"

next, please.

jephthah 1,888 Posting Maven

i thought this thread was about "strangling newbies"

imagine my dismay when i found a ten-mile long post full of incoherent code with no syntax coloring.

jephthah 1,888 Posting Maven

If you can't figure out how to get character input from the keyboard, YOU DAMN SURE SHOULDN'T BE USING MALLOC.

first learn basic programming first before starting a career in writing shitty code full of memory leaks, mmkay?

jephthah 1,888 Posting Maven

the best way to figure out RS232 is, as you have found out, to hack through it yourself.

those constants you asked about are #defined in the header file.

to get an accurate delay, you can run a huge for loop and measure the realtime elapsed. then derive a value based on the results that will allow you to delay an arbitrary amount.

jephthah 1,888 Posting Maven

if you have a source file for this programme please attach it.

ahahahahahahahahahahahah


(pause, breathe)

ahahahahahahahahahahahahah


seriously. gtfo.


.

jephthah 1,888 Posting Maven

In certain cases when dealing with text files or reading data from a "character device", the Microsoft MS-DOS shell (COMMAND.COM) or operating-system utility programs would historically append an ASCII control-Z character (aka the "SUB" character, 0x1A) to the end of a disk file

--source: wikipedia

jephthah 1,888 Posting Maven

wait a minute... are you trying to open a *website* or are you trying to open a harddrive through Internet Explorer

if youre talking about a website.... then you'll need to be getting quite familiar with either the winsock.h or sockets.h library, depending on your OS.

if you're talking about opening a file from your hard drive via Internet Explorer, using C... that's a completely backasswards idea. you need to get that out of your head, right now -- for way too many reasons to list here.

.

jephthah 1,888 Posting Maven

Not necessarily. Without knowing what needs to be done, looking up a function generally is not of much help. After your explanation, your solution is readily apparent.

I'm not really criticizing your recommendation, just that how you meant to use it is a good thing to add.

what, you mean people cant read my mind?

:P

i do have a problem, sometimes, with being too terse. thanks for the reminder.

jephthah 1,888 Posting Maven

the main point of contention here, is that they have provided zero evidence they have even *attempted* to work on their problem on their own.

this is the signature pattern of a many typical posters here: they cut and paste their homework assignment in the hope that someone will do it for them.

jephthah 1,888 Posting Maven

here's something fun to do: create a program that encrypts/decrypts messages by hiding/extracting them from a JPG image.

I'm not talking about just "hiding messages" in the exif header, which would be easily detected by any network sniffer. I mean actually changing a relatively small percentage of the bytes to be later assembled into a message.

as you probably know, JPGs are lossy, so if you were to manipulate only 1 out of 100 bytes, it would just add a bit more noise to an already somewhat noisy picture. thus a 100KB image could have roughly a 1KB message embedded in it.

the most simple version would just replace a single JPG byte for an ASCII byte -- making sure you take care not to corrupt the frame of the JPG file itself.

slightly better would be to only use the lower 7 bits, leaving the MSB at its original state. also important would be to not plop your "code bytes" in the middle of large fields of 0x00 or 0xFF byte patterns.

better still would be "chopping up" the code bytes so they only replace certain bit fields (or single bits!) that would cause less noticeable shifts in the picture quality. This would of course reduce the amount of message one could put in any given JPG file

improve it even more, by making the ordering of the "code bytes" to be pseudo-random... instead of having them be placed every 1 out of …

jephthah 1,888 Posting Maven

^ let it go, dude

jephthah 1,888 Posting Maven

some conditions inside a function call is not met and you need to exit and miss the malloc'd memory that was allocated initially.

yeah, that's a common event causing memory leaks.

so my point was that merely counting 'x' number of malloc() and 'x' number of free() commands does not indicate that your memory allocation is somehow going to be free of leaks.

if you must use memory allocation, do something similar to what AncientDragon earlier posted: replace malloc() and free() with your own functions that include a tracking mechanism such as a linked list

jephthah 1,888 Posting Maven

BANERJEEEIN,

what DRAGON said... compile it and find out.

how hard is that?

jephthah 1,888 Posting Maven

my point is that STRSTR function will do what the OP wants

i thought it would be readily apparent to anyone who takes a moment to look it up. sorry, if i don't type out a fully commented and validated solution.

Essentially the solution is this:

get one line at a time with FGETS, then use STRSTR to see if a certain string (such as the particular "id_no") is found within the line. if not, then read the next line. if it is, well, there's your line.

i'll leave typing out the code as an exercise for the reader.

Aia commented: I am stupendous man and I approve of this message. ;) +9
jephthah 1,888 Posting Maven

simply.

amazing.

:P

jephthah 1,888 Posting Maven

Huge Program Due: August 10th.
Percent compete: 0%.
Strategy: wait til August 8th, then Teh Internets will save me.

LOL same shit, different day.

.

jephthah 1,888 Posting Maven

other than the fact that you're confusing linear functions with linear equations, a huge problem can be located in the title of your thread:

"Turbo C"

throw that crap away, now, and get a real compiler. and if you have an instructor who insists you use Turbo C, them them to sod off, as well.

all they're doing with Turbo C, in ensuring you will be a worthless programmer and incompetent in the global workplace.


.

jephthah 1,888 Posting Maven

Is this an assignment, just to go through and count occurrences of these particular functions within some *.c file?

I ask, because for most "REAL WORLD" programs you can't just merely write a script that counts the occurrences of malloc with the occurances of free and check that they're equal.

real world programs are not always nice and neat with a free following every malloc like how you expect HTML files always to always have a "close tag" occuring somewhere inline after its corresponding "open tag".

typically memory leaks occur because the program logic often calls functions or conditionally executes blocks of codes that contain either a malloc or a free -- but not both -- and the programmer misses some unexpected condition in the logic and therefore makes (or forgets) an unaccounted call to malloc or free.

memory allocation problems is the bane of program debugging. there are far too many programmers out there who think they're somehow "cool" because they use malloc, even though 99% of the time they don't need to.

combine this with the fact that many of these characters tend to write sloppy, convoluted code, and you'll begin to understand Why I F-ing Hate Malloc

.

jephthah 1,888 Posting Maven

yeah, what CHASTER said:

the header file should only contain
(1) function prototypes
(2) defines
(3) macros

the functions themselves should be written in the *.c file.

jephthah 1,888 Posting Maven

i know you are asking about functions, but an important thing about static, is that when you scope a local variable as such, it will retain its value across repeated calls to the function where it is declared. this is very important when creating functions, espeically if they are intended to be imported into larger projects.

you can also make a static global variable that will retain its value and be visible to all functions with the *.c file, but no functions anywhere else, much like how DRAGON described the static-scoped function

jephthah 1,888 Posting Maven

mancode,

look into the use of the "strstr" function.

jephthah 1,888 Posting Maven

i see nothing much has changed since ive been gone.

Salem commented: In a world of change, it's nice to have constants :) +20
jephthah 1,888 Posting Maven

Oh, Spring battles, ye of great import

how petty doth thou parries and thrusts

appear from the height of Midsummer


.