When I execute the next code it runs fine
// Example program
#include <string.h>
#include <stdio.h>
int main()
{
char *dbString = strdup("172.0.0.1:5000");
char *port = strchr(dbString, ':');
printf("port = %s\n", port);
if (port)
*port++ = '\0';
printf("port = %s\n", port);
return 0;
}
But if I execute the next code I got an error.
// Example program
#include <string.h>
#include <stdio.h>
int main()
{
char *port = (char*) ":5000";
printf("port = %s\n", port);
if (port)
*port++ = '\0';
printf("port = %s\n", port);
return 0;
}
Could you explain to me the reason for the error?