Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Getting an error

Getting an error

Scheduled Pinned Locked Moved Managed C++/CLI
help
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shamnar
    wrote on last edited by
    #1

    :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

    2 1 Reply Last reply
    0
    • S Shamnar

      :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

      2 Offline
      2 Offline
      2bee
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • 2 2bee

        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

        S Offline
        S Offline
        Shamnar
        wrote on last edited by
        #3

        oh........ thanks for this valuable help its get ok when i initialised it as u suggest thanks thanks thanks a lot shamnar

        S 1 Reply Last reply
        0
        • S Shamnar

          oh........ thanks for this valuable help its get ok when i initialised it as u suggest thanks thanks thanks a lot shamnar

          S Offline
          S Offline
          Shamnar
          wrote on last edited by
          #4

          :^) 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

          2 1 Reply Last reply
          0
          • S 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

            2 Offline
            2 Offline
            2bee
            wrote on last edited by
            #5

            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

            S 1 Reply Last reply
            0
            • 2 2bee

              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

              S Offline
              S Offline
              Shamnar
              wrote on last edited by
              #6

              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

              2 1 Reply Last reply
              0
              • S 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

                2 Offline
                2 Offline
                2bee
                wrote on last edited by
                #7

                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

                S 1 Reply Last reply
                0
                • 2 2bee

                  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

                  S Offline
                  S Offline
                  Shamnar
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups