Help....
-
Why Insert and Delete is not working? char *convert_char_modifier(char *Modifier) { int i; char ch; for (i=0; i < strlen(Modifier);i++) { ch = Modifier[i]; switch (ch) { case 'A': //Delete(i); //Insert(i,"01"); break;:(( :(( sardinka
Apart from the fact they are commented out? I think we'll need to see the code for Delete and Insert too. Michael :-)
-
Apart from the fact they are commented out? I think we'll need to see the code for Delete and Insert too. Michael :-)
I comment that line out, but even if I uncomment that line it will not work. My code is below: char *convert_char_modifier(char *Modifier) { int i; char ch; for (i=0; i < strlen(Modifier);i++) { ch = Modifier[i]; switch (ch) { case 'A': Insert(i,"01"); break; case 'B': Delete(i); Insert(i,"02"); break; } } return(Modifier); :((
-
I comment that line out, but even if I uncomment that line it will not work. My code is below: char *convert_char_modifier(char *Modifier) { int i; char ch; for (i=0; i < strlen(Modifier);i++) { ch = Modifier[i]; switch (ch) { case 'A': Insert(i,"01"); break; case 'B': Delete(i); Insert(i,"02"); break; } } return(Modifier); :((
Did you see the code I posted to your earlier question? The reply wasn't actually to you, but to someone else who had replied to your original message. Check it out. By the way, it looks like you're trying to mix CString methods with a simple char array. beyond that, what happens for lower case alpha characters, or characters that aren't letters at all? You have no code to handle those possibilities. Is this a homework assignment? "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
-
I comment that line out, but even if I uncomment that line it will not work. My code is below: char *convert_char_modifier(char *Modifier) { int i; char ch; for (i=0; i < strlen(Modifier);i++) { ch = Modifier[i]; switch (ch) { case 'A': Insert(i,"01"); break; case 'B': Delete(i); Insert(i,"02"); break; } } return(Modifier); :((
Gosh, you're doing it the hard way, aren't you ? Like John said, check out the code he posted in reply to my comment ( which was essentially to do what John has shown you, build a second string ). Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
-
Why Insert and Delete is not working? char *convert_char_modifier(char *Modifier) { int i; char ch; for (i=0; i < strlen(Modifier);i++) { ch = Modifier[i]; switch (ch) { case 'A': //Delete(i); //Insert(i,"01"); break;:(( :(( sardinka
This is a solution in plain C. If this is a homework, you should really make sure that you understand the code, and then rewrite it from memory. You will not learn anything otherwise. Also note that more memory than needed may be allocated (what can you do about that?). After seeing some horrible previous posts (think calculator ;P) I had to answer this one to show that a *little* politeless could get you far... /moliate starting to sound 50 year older now, better quit...
char* convert_char_modifier(char *Modifier)
{char* tmp = new char[strlen(Modifier)*2];
char* Result = tmp;for (;*Modifier; Modifier++)
{if (*Modifier >='A' && *Modifier <= 'Z')
{*tmp++ = char((*Modifier - 'A')/10+'0');
*tmp++ = char((*Modifier - 'A')%10+'1');
}
else
*tmp++ = *Modifier;
}*tmp = '\0';
return Result;
}int main(int argc, char* argv[])
{ char* Modifier = "A79867B987C98ZZ";
printf("%s\n", convert_char_modifier(Modifier) ); // returns 01798670298703982626
return 0;
}