jephthah 1,888 Posting Maven

i'm just wondering, "where's the love?"

jephthah 1,888 Posting Maven

oh, sorry, i didnt really look at your code.

the problem is your use of continue, the logic is all screwed up.

you keep trying the key until you find a non-match at which point you copy the character. since you'll always find a non-match, you'll never skip any characters.

anyhow this thread is solved. i think we're done here.

jephthah 1,888 Posting Maven

it just.

doesn't.

stop.

William Hemsworth commented: Haha :D +9
jephthah 1,888 Posting Maven

because you're declaring key as a pointer to uninitialized memory. change it to key[11]

jephthah 1,888 Posting Maven

actually, the fact that you're incrementing j++ within the for loop is okay. i thought 'j' was a loop control variable.

but, still, you should only increment the index after you've checked all the key characters.

you pretty much had it done. so, here's what i did, keeping with your original attempt. if i had to write it from scratch, i would have used pointers rather than index, but i guess it's all about the same. also, note that it's not especially fault tolerant, but you get the idea.

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

void remove(char *myStr, char *myKey);

int main(void)
{
   char source[256];
   char key[40];

   printf("enter string to search: ");
   fgets(source,sizeof(source),stdin);

   printf("enter chars to remove:  ");
   fgets(key,sizeof(key),stdin);

   remove(source, key);
   printf("Result: [%s]\n\n", source);

   printf("  Press any key ...\n");
   getchar();
   return 0;

}
void remove(char *myStr, char * myKey)
{
   int in=0, out=0, k=0, match=0;

   for (in=0; myStr[in] != '\0'; in++)
   {
      match = 0;

      for (k=0; myKey[k] != '\0'; k++)
         if (myStr[in] == myKey[k])
            match = 1;

      if (match == 0)
         myStr[out++] = myStr[in];
   }

   myStr[out] = '\0';
}

PS: dont use "fflush(stdin)"


.

jephthah 1,888 Posting Maven

that doesnt help him if his password is supposed to be EXACTLY seven characters, now does it?

and this is C, not C++

jephthah 1,888 Posting Maven

you're increasing j++ every time it doesnt make a single character match within the key, which is messing your count up.

and its a bad idea to incrment a for loop counter within the loop itself unless you know what youre doing.

you should increment your pointers only after you've checked every single key character.

if there was a match then only increment the "input" pointer that reads along the string.

if there wasnt any matches out of all the key characters, then and only then do you copy the the input character to the output character, and also increment BOTH pointers.

jephthah 1,888 Posting Maven

use "strlen" and check character ranges. look at your ascii table.

post some code if you want any more advice.

jephthah 1,888 Posting Maven

plz someone reply me quickly

well, i was getting ready to reply, but then i got to that last part and just lost interest.

jephthah 1,888 Posting Maven

no it's not portable. there is no truly portable solution. you'll have to #define the sleep routine according to the detected OS at build time.

jephthah 1,888 Posting Maven

HERE is how you do it:

use two pointers. an input and an output, both pointing to the start of the source string.

compare the input pointer character to each of your key characters. if you have a match, increment your input pointer only. if you dont have a match, then copy the input pointer character to the output pointer location, and increment BOTH pointers.

once you evaluate the last source character pointed to by the input pointer, NULL terminate the source string at the output pointer.

your source string now contains only the characters NOT matching any characters in your key. in other words, the key characters have all been removed from your source.


.

jephthah 1,888 Posting Maven

or if you use FF and ABP, you dont ever have to worry about any site ads, anywhere, ever.

JugglerDrummer commented: That was sooo helpful! that extension is amazing!! +1
jephthah 1,888 Posting Maven

maybe its a problem with ESL but i dont know WTF the OP is saying.

scru commented: I can never quite figure it out myself either +6
jephthah 1,888 Posting Maven

goats are awesome. they can just clear right through thorny blackberry bushes in no time. dandelions are gone, too.

they're a really popular alternative even in the city. here in seattle, we have some neighbors who have goats and rent them out.

jephthah 1,888 Posting Maven

^ to expand on what Narue just said: the "runtime stack" contains some basic info including the return addresses where the program is supposed to return to .... so you probably overwrote it, wiping out the return address that main was trying to "go" to.... many runtime environments (including one that i use regularly) wouldn't even let that offending line of code be exectued.

...

to help you conceive of the whole thing, think of pointer addreses like mailing addresses. when the postal carrier has a huge box for you, they cant put it in your mailslot. so instead, they put a note in your mailslot telling you they have a huge box for you at some other location that you have to go to in order to retrieve it.

the "mailslot" is the container of the physical pointer, and the "note" is the information that points you where to go. And what you did, was crammed a cubic meter box into a 2 centimeter wide mailslot.

following the analogy to it's conclusion, you can't do that without breaking the structure of the building.

.

jephthah 1,888 Posting Maven

I'm jealous of your jello shots.

jephthah 1,888 Posting Maven

humanity will be reduced to scavaging and cannibalism. roving bands of blood cults will enslave others as catamites. women will be subjected to birthing babies as a food source.

jephthah 1,888 Posting Maven

I can't seem to understand why it caused this kind of problem, in the first place.

undefined behavior.

some environments would not allow the offending command to even execute. yours allowed it to execute, but not to return from main.

simply put, the prototype for memcpy requires pointers for the source and destination. you supplied a pointer to a pointer.

jephthah 1,888 Posting Maven

nm

jephthah 1,888 Posting Maven

oh, i wasnt aware of that.

i guess the only time i ever concern myself with reducing cycle times is in embedded applications, and there i rarely deal with strings and newlines.

but thats useful to know. thanks.

jephthah 1,888 Posting Maven

ArkM's method is sufficient, but i prefer this way.

buf[strcspn(buf,'\n')] = '\0';

it's just a single line of code that will replace the newline with a NULL, if a newline is found, or will do nothing if one is not there

.

jephthah 1,888 Posting Maven

oh my jesus. dont' take it personal, i wasnt' attacking you.

although ... i guess if i look at my post now, it does seem a bit snarky. sorry. it wasnt meant to be taken serious.

just a comment that syntax highlighting is like any other thing such as broadband or cellphones... you don't think you need it, you think it's just a trivial thing, then you get used to it and you find that you cant live without it.

and when i say "you" i really mean "me"

:P

jephthah 1,888 Posting Maven

* well, hell, i dont care really. im just trying to think of something that is easy to implement and wont break the existing pages. line numbers are fine.

^^ the point is, i just can't stand having to look at non highlighted code. its frustratingly unreadable. it makes no difference if i "used to" program BASIC on a green monochrome terminal.

people used to post to BBS and USENET using a 4800 baud modem. now are you gonna hate on them darn kids with their broadband and streaming video? syntax highlighting has been around 10 or 15 years. do you really want to go back? well lets go back to punch cards and paper tape, then

jephthah 1,888 Posting Maven

glad you got it figured out. dont worry about the double posting. it happens to almost everyone at some point, somewhere.

there are worse things one could do. :)

jephthah 1,888 Posting Maven

cycle through each lettter in the alphabet, a through z, and check each letter if it repeats.

remember that ascii code character A is decimal 65 and Z is decimal 90. lowercase a is decimal 97 and lowercase z is 122. you can subtract 32 from any lowercase letter to get its uppercase version.

jephthah 1,888 Posting Maven

PROBLEM:

noobs are continually posting mountains of unhighlighted code, and its just nearly impossible to read such messes without highlighting... i dont even want to try, it hurts my head.

making this worse is the people who need the most help are the same people who are the worst offenders. often times, their errors are something simple syntax or typo error, and could easily be spotted if we could just read it.

It's bad enough getting them to use [code] tags in the first place. But I cant keep bitching at new guys or gals because they dont know to use specific syntax highlighting.


SOLUTION:

by default, unspecificed [code] tags will *always* use the syntax highlighting for whatever the particular forum happens to be. this will be backwards compatible, because all specific code syntax will continue work as normal. if there's not already an option, allow something like to just be plain vanilla text.

[B][U]EXAMPLE[/U][/B]

for the C code forum,

[noparse][code][/noparse] prints C-syntax highlighting [code=c] prints C-syntax highlighting [code=php] prints PHP highlighting [code=plain] prints plain text (no highlighting)

whereas for the PHP forum

[noparse][code][/noparse] prints PHP-syntax highlighting [code=c] prints C-syntax highlighting [code=php] prints PHP highlighting [code=plain] prints plain text (no highlighting)

et cetera...

.[code=plain] to just be plain vanilla text.


EXAMPLE

for the C code forum,

[code] prints C-syntax highlighting
prints C-syntax highlighting [code=php] prints PHP highlighting [code=plain] prints plain text (no highlighting)

…
Nick Evan commented: You've got my vote! +16
tux4life commented: Mine also :) +3
jephthah 1,888 Posting Maven

doh!

jephthah 1,888 Posting Maven

what's the problem saving the data? as in, what's it doing or not doing that doesn't seem right to you?

if you want a new file to be written with the data, then you're using fopen correctly.... "w" (write) will delete the contents of the existing file, if any, before writing the new data.

if you want the file to continually add new data to the existing file, then you need to use "a" (append) as poster above noted.

otherwise, the only other problem that could be happening, is that your double floating point array being passed into E_Data might not be containing what you think it should be. for instance if it's uninitialized, any number of weird behaviors could be occuring.

jephthah 1,888 Posting Maven

you've had 5 separate threads in the past month on this same program.

and theres no functional difference between this program and the one you posted four days ago with Narue.

i'm just sayin'

jephthah 1,888 Posting Maven

(1) this thread was dead and buried, until "lolguy" dug up the bloated corpse to defile it even further

(2) the original code is an example of what not to do. don't spend any time thinking about it.

WaltP commented: Kicking a dead horse two days after it died a second death. -3
Aia commented: Not excessive +15
jephthah 1,888 Posting Maven

I've been trying to figure out how to make the code highlighted as you can see I didn't get how I could do it lol.

FYI

[code=c] stuff here will be syntax-highlighted

[/code]

:)

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

any int variable is inherently an *integer* the value is not stored in any particular base .... hex or decimal or binary, it doesnt matter. the only difference is when you print it. printf("hex value %04X = decimal value %d\n",Dec, Dec); but also, what youre asking to do is to concatenate an upper byte to a lower byte. or you could also say you're adding a left-shifted value to another value.

you could do it like this: Dec = (TH1 << 8) + TL1; .

tux4life commented: Yep, an integer is an integer :) +4
jephthah 1,888 Posting Maven

Hi, don't ever send emails like the ones to me! ok.

...

jephthah

what are you talking about? i dont know you and wasn't talking to you, so take my name out of your mouth.

i thought you were leaving anyhow? dont let the door hit you in the ass on the way out.

jephthah 1,888 Posting Maven

well, knowing your exact requirements changes the nature of what would be an efficient solution.

the way i described above was more of an abstract exercise on a general "how else could i do _____" sort of thing. it may be somewhat clever, but there may be other solutions that are more appropriate.

though given what you've described, it sounds like memory and speed are not an issue for your processor at all --- that you're really just trying to keep a printer from spilling rolls of paper every time some remote alarm goes off.

I know the Comp Sci folks will probably sh*t kittens if i say this, but being familiar with remote monitoring industury, i know it tends to be that any solution that gets the job done is a good solution. :P


.

jephthah 1,888 Posting Maven

well, on second look, any claims to speed improvement is completely dependent on how this is used.

because while it's faster to "store" the bytes in memory, it will be slower to retrieve all bytes currently stored. so... will depend on how you need to access the data. if you have high throughput on collection and less need to access, it will be better than if you collect less and access frequently.

the worst case is if you have frequent access requirements and just a few possible bytes that can be stored, the sparsely filled memory would make this method considerably slower.

still, it is more memory friendly: rather than storing 100 bytes in 100 bytes of memory, you get 256 effective bytes of "storage" for 32 bytes of memory. compression of 8:1. how important is that? eh, probably not too much depending on how much memory you have available.


.

jephthah 1,888 Posting Maven

um, i was just saying, i thought your post sounded biased as if non english speakers were stupid, and if they just learned some more things, they would magically speak better.

but youve explained that you didnt mean it the way it sounded.

as for me, i'm way over sensitive sometimes and i think i need to adjust my meds. or cut back on caffeine. or have more sex. or something.


sorry for being a jerk. ok?


.

jephthah 1,888 Posting Maven

check this out i think you'll see what i mean

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

#define RECEIVED_SERIAL_BYTE(x) { byte[x/8] |= (1 << (x%8)); }

unsigned char byte[32];  // embedded memory location

int main(void)
{
   char buf[5];
   int i, j, value;


   while(1)
   {
      do 
      {
         printf("\ninput decimal value 0-255: ");
         fflush(stdout);
         fgets(buf,sizeof(buf),stdin);
         errno=0;
         value = strtol(buf,NULL,0);
         if (errno)
            perror(NULL);
      } while (errno);

      if (value<0 || value>255) // out of range value will quit loop
      { 
         printf("quit requested.\n");
         break;
      }

      RECEIVED_SERIAL_BYTE((unsigned char)value);  // store value 

      printf("\n+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\n");
      for (i=0; i<32; i++)                 // dump entire memory contents
      {
         for (j=0; j<8; j++)
            if (byte[i] & (1 << j))
               printf(" %02X",i*8+j);
            else
               printf("   ");
         for (i++, j=0; j<8; j++)
            if (byte[i] & (1 << j))
               printf(" %02X",i*8+j);
            else
               printf("   ");
         printf("\n");
      }
      printf("+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\n\n\n\n");
   }

   return 0;
}

.

jephthah 1,888 Posting Maven

do you need to be limited to storing 100 bytes? because if you kept a record of all possible 256 bytes, you could make it both faster and more memory-efficient.

example: instead of actually copying and storing the value of 256 (or even 100) separate bytes, you really only need to store 32 bytes. for a total of 256 bits. where each bit is a placeholder representing the value of the potential received byte. and each of these bits is set to 1 if it the byte value it represents has been received, or 0 if it has not.

so you've got byte[0] - byte[31], where:

bit 0 of byte[0] represents serial byte value 0x00
bit 7 of byte[0] represents serial byte value 0x07
bit 0 of byte[1] represents serial byte value 0x08
bit 7 of byte[1] represents serial byte value 0x0F
...
bit 0 of byte[31] represents serial byte value 0xF8
bit 7 of byte[31] represents serial byte value 0xFF

i think you'll best accomplish this mulitplexing with a macro.

jephthah 1,888 Posting Maven

i used this library several years ago for a project... it's quite impressive.... however, i don't really remember anything to help you with.

so, i don't want to sound dismissive, but i think this sort of highly specialized library you'll probably find more precise help on their mailing list or archives

http://gmplib.org/#MAILINGLISTS

jephthah 1,888 Posting Maven

it happens to everyone. i covered for you.

jephthah 1,888 Posting Maven

yeah... email is easy to misinterpret, what with the whole lack of non-verbal context and stuff.

we should both take a lesson from that, you and I.

jephthah 1,888 Posting Maven

I can't call the function multiple times bc in destroys my maze after one go I'm was trying to think of how to do it without compromising my maze.

all you have to do is store the original maze in memory and recall it each time with the new person's position.

you've been handed 90% of the solution and 99% of the difficulty. all you need to do now is construct a for or while loop to implement it several times.

iamthwee commented: *yup* +19
jephthah 1,888 Posting Maven

eh... when one power falls another one will rise to take its place.

I'll agree, though. flying under the radar has its advantages.

jephthah 1,888 Posting Maven

okay.

i agree that, in the spirit of P.T. Barnum, kelechi gave a mighty fine answer.

cheers.

.

jephthah 1,888 Posting Maven

what if the user try to enter lots of no. and then press a key maybe "b" to stop and it generate the sum of all the users input

i think that's a good idea.

use a non-numeric character (like 'b' or whatever) as the sentinel to stop taking input

and if you want to get fancy, you could use the '+', '-', '=' characters as inputs to perform the functions you want to do.

i mean, isnt that what you're trying to do here? program a basic adding machine?


.

jephthah 1,888 Posting Maven

why would you ever want to enable safe search? internet without noodz? maaaaan, that's about as fun as a box of ... er as fun as .... well look, that's just not any fun.

were you always picked to be hall monitor in school?

GrimJack commented: Heh,heh - love your sense of humor! +9
jephthah 1,888 Posting Maven

no, i guess you weren't born yet.

:(

jephthah 1,888 Posting Maven

okay. sorry. his implementation of the basic sentinel concept is just fine.

but a calculator that spontaneously shuts down when you try to add 9999... well, it just isn't going to sell really well.

i'm just saying

jephthah 1,888 Posting Maven

here's your problem

char *line;
while(fgets(line,20,fp1))

you cant write data to an uninitialized pointer.