Getting an error
-
:confused: hi,all i am a new comer to this group While programming i got an error which is some reference error or some thing else Anyways i will give u my doe pls help me #include #include #include char* rmstr(char *whstr, char *strm) { char *ptr,*rem; char temp[20]; clrscr(); int k=0; do { ptr=strstr(whstr,strm); if (ptr==NULL) { break; } for (int i=0;i
-
:confused: hi,all i am a new comer to this group While programming i got an error which is some reference error or some thing else Anyways i will give u my doe pls help me #include #include #include char* rmstr(char *whstr, char *strm) { char *ptr,*rem; char temp[20]; clrscr(); int k=0; do { ptr=strstr(whstr,strm); if (ptr==NULL) { break; } for (int i=0;i
Would you mind posting it again? But this time please check "Ignore HTML tags in this message (good for code snippets)" because the code you've posted is currently incomplete. for instance: >> for (int i=0;i{ >> temp[k++]=whstr[i]; >> } btw. The line below is probably causing your trouble. strcpy(rem,whstr); The rem pointer has not been initialized before or to be more precise you haven't allocated any memory, even though you're applying strcpy on it. cheers Tobias
-
Would you mind posting it again? But this time please check "Ignore HTML tags in this message (good for code snippets)" because the code you've posted is currently incomplete. for instance: >> for (int i=0;i{ >> temp[k++]=whstr[i]; >> } btw. The line below is probably causing your trouble. strcpy(rem,whstr); The rem pointer has not been initialized before or to be more precise you haven't allocated any memory, even though you're applying strcpy on it. cheers Tobias
-
oh........ thanks for this valuable help its get ok when i initialised it as u suggest thanks thanks thanks a lot shamnar
:^) sir this time i met with another problem. that is if my input to the fn is "thisa" "is" then i am getting o/p "thisa" instead of "tha" please help me. now i am sending the code along with this mail #include #include #include char* rmstr(char *whstr, char *strm) { char *ptr,*rem=""; char temp[10]; clrscr(); int k=0; do { ptr=strstr(whstr,strm); if (ptr==NULL) { break; } for (int i=0;i
-
:^) sir this time i met with another problem. that is if my input to the fn is "thisa" "is" then i am getting o/p "thisa" instead of "tha" please help me. now i am sending the code along with this mail #include #include #include char* rmstr(char *whstr, char *strm) { char *ptr,*rem=""; char temp[10]; clrscr(); int k=0; do { ptr=strstr(whstr,strm); if (ptr==NULL) { break; } for (int i=0;i
Hi, as I said before, look at your memory allocation. // this won't work unless you initialize *temp char *temp; stcpy(temp,rmstr("thisa","is")); // for instance char *temp = new char(256); strcpy(temp,rmstr("thisa","is")); Oh, and by the way this won't work either: char *ptr,*rem="" you have initialized that rem pointer, but with a reference to an empty string. As long as there is no memory assigned to it strcpy(rem,whstr); will fail. In addition I would really recommend you to have a look into a C/C++ tutorial, because this knowledge is essential. regards Tobias -- modified at 2:06 Monday 27th March, 2006
-
Hi, as I said before, look at your memory allocation. // this won't work unless you initialize *temp char *temp; stcpy(temp,rmstr("thisa","is")); // for instance char *temp = new char(256); strcpy(temp,rmstr("thisa","is")); Oh, and by the way this won't work either: char *ptr,*rem="" you have initialized that rem pointer, but with a reference to an empty string. As long as there is no memory assigned to it strcpy(rem,whstr); will fail. In addition I would really recommend you to have a look into a C/C++ tutorial, because this knowledge is essential. regards Tobias -- modified at 2:06 Monday 27th March, 2006
could you send me a function which accepts two strings as i/p and returns another string which doesnt contain the second string in first string for eg if i call like this rmstr("this","is") it should return "th" sir please dont use std::string because my compiler is not supporting it anyways thanks for ur valuable help, let me acknowledge for ur kindness to spend time for this. shamnar
-
could you send me a function which accepts two strings as i/p and returns another string which doesnt contain the second string in first string for eg if i call like this rmstr("this","is") it should return "th" sir please dont use std::string because my compiler is not supporting it anyways thanks for ur valuable help, let me acknowledge for ur kindness to spend time for this. shamnar
Shamnar, let me guess, that is your homework??? I mean it is a little obvious if you say that you cant use std::string due to your compiler. Well it might be or not, however those pointer stuff is essential. I do understand that it is quite weird stuff but it won't get you far if don't how to deal with it. However, i've just programmed that function. But to make it not too easy i have removed some parts from it. char* rmstr(char* searchstring, char* morphem) { char* tmp; char* resultstring = new char(strlen(searchstring)); *resultstring = '\0'; while( ( tmp = strstr(searchstring, morphem)) ) { int len ...; char* result = new ...; strncpy(...); searchstring = (...); *(result+len) = '\0'; strcat(...); } return resultstring; } Tobias
-
Shamnar, let me guess, that is your homework??? I mean it is a little obvious if you say that you cant use std::string due to your compiler. Well it might be or not, however those pointer stuff is essential. I do understand that it is quite weird stuff but it won't get you far if don't how to deal with it. However, i've just programmed that function. But to make it not too easy i have removed some parts from it. char* rmstr(char* searchstring, char* morphem) { char* tmp; char* resultstring = new char(strlen(searchstring)); *resultstring = '\0'; while( ( tmp = strstr(searchstring, morphem)) ) { int len ...; char* result = new ...; strncpy(...); searchstring = (...); *(result+len) = '\0'; strcat(...); } return resultstring; } Tobias
finaly i did it. thanks for ur advices and clues u have given to me. but i made one more instruction. i am sending it along with this char* rmstr(char* searchstring, char* morphem) { char* tmp; char* resultstring = (char *) malloc(strlen(searchstring)); *resultstring = '\0'; while( ( tmp = strstr(searchstring, morphem))!='\0')// ) { int len=strlen(searchstring)-strlen(tmp); //...; char* result = (char *) malloc(len);//...; strncpy(result,searchstring,len);//...); searchstring = tmp+strlen(morphem);//(...); *(result+len) = '\0'; strcat(resultstring,result);//...); free (result); } if (searchstring!='\0') strcat(resultstring,searchstring); free (resultstring); return resultstring; } thanks for make me to study pointers. shamnar