Link to home
Start Free TrialLog in
Avatar of akohan
akohan

asked on

question on using strstr and strncpy

Hello,

I'm using following code but in runtime I get a segmentation fault message.  I'm trying to learn how find a substring in a string and replace with something or "".

Thanks.

#include <stdio.h>
#include <string.h>
 
int main(void)
{
 
  char* d1 = "http://www.test.com";
  char* d2 = "https://www.test.com";
  char* d3 = "https://test.com";
 
  char* pch;
  pch = strstr(d1,"http://");
  strncpy(pch, "xyz", 3);
 
  printf("\nresult = %s", pch);
 
  return 0;
}
~

Open in new window

SOLUTION
Avatar of dlinvill
dlinvill

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial