character pointers

Status
Not open for further replies.

Thread Starter

sall

Joined Jul 13, 2011
10
I wrote the following code (c language) to omit the alphabet 'l' from string "hello" and print the resultant string without holes using pointers.it printed garbage values then caused the compiler to stop working.
#include <stdio.h>
#include <iostream>
int main ()
{ char*p="hello";
int i;
(p) =(char*)malloc(20);/*assigning memory of 20 bytes*/
for (i=0;i<5;i++)
{if (*(p+i) = 'l')
{
free(p+i);}}/*i tried to free the specific memory containing alphabet l*/
puts(p);
system("pause");/*to pause the console window*/
return 0;}

can someone tell what mistake is there with this code or the correct code to omit the alphabet 'l' from string "hello" and print the resultant string using pointers ?
 
Status
Not open for further replies.
Top