LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   i tried using this code for deleting a user given character from a user given string (https://www.linuxquestions.org/questions/linux-newbie-8/i-tried-using-this-code-for-deleting-a-user-given-character-from-a-user-given-string-884498/)

mecrazyme1234 06-04-2011 08:27 AM

i tried using this code for deleting a user given character from a user given string
 
#include<stdio.h>

#include<string.h>

char* reverse (char*,char);


int main()

{

char *name;

char *ch=name;

char c;

printf("\nEnter the string to be reversed and the character to be deleted");

scanf("%s%c",name,&c);

char* ret=reverse(ch,c);

printf("\nthe modified string is %s",ret);

return(0);

}





char* reverse (char* p,char t)

{ int l,i;

l=strlen(p);

printf("\n%d",l);

for(i=0;i<l;i++)

{

if(*p=='t')

{
while(*p!='\0')


{ *p=*(++p);

p++;

}


}

p++;

}

printf("%s",p);

return(p);
}
******************************************************
but it showed segmentation error..please help

EricTRA 06-04-2011 08:43 AM

Hello,

Please don't double/cross post your question in more than one forum. That will only confuse you and us on where the conversation is taking place. Stick to your thread in the Programming forum. Reported as duplicate of this one.

Kind regards,

Eric

Tinkster 06-04-2011 04:59 PM

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Closed the original in favour of the more sensibly formatted & placed dupe:

http://www.linuxquestions.org/questi...string-884501/


All times are GMT -5. The time now is 07:04 PM.