#include <iostream>
#include <string.h>
#include <string>
using namespace std;
int main(void)
{
const char* argument = "Hey you guys";
string str;
str.append(argument);
str.replace(str.find("guys"), 5, "Girls!");
cout << str;
}
Hey you Girls!
$ cat rompmote.c
#include <string.h>
#include <time.h>
#include <stdio.h>
#include "merc.h"
void do_pmote( CHAR_DATA *ch, char *argument )
{
CHAR_DATA *vch;
char *letter,*name;
char last[MAX_INPUT_LENGTH], temp[MAX_STRING_LENGTH];
int matches = 0;
if ( !IS_NPC(ch) && IS_SET(ch->comm, COMM_NOEMOTE) )
{
send_to_char( "You can't show your emotions.\n\r", ch );
return;
}
if ( argument[0] == '\0' )
{
send_to_char( "Emote what?\n\r", ch );
return;
}
act( "$n $t", ch, argument, NULL, TO_CHAR );
for (vch = ch->in_room->people; vch != NULL; vch = vch->next_in_room)
{
if (vch->desc == NULL || vch == ch)
continue;
if ((letter = strstr(argument,vch->name)) == NULL)
{
act("$N $t",vch,argument,ch,TO_CHAR);
continue;
}
strcpy(temp,argument);
temp[strlen(argument) - strlen(letter)] = '\0';
last[0] = '\0';
name = vch->name;
for (; *letter != '\0'; letter++)
{
if (*letter == '\'' && matches == strlen(vch->name))
{
strcat(temp,"r");
continue;
}
if (*letter == 's' && matches == strlen(vch->name))
{
matches = 0;
continue;
}
if (matches == strlen(vch->name))
{
matches = 0;
}
if (*letter == *name)
{
matches++;
name++;
if (matches == strlen(vch->name))
{
strcat(temp,"you");
last[0] = '\0';
name = vch->name;
continue;
}
strncat(last,letter,1);
continue;
}
matches = 0;
strcat(temp,last);
strncat(temp,letter,1);
last[0] = '\0';
name = vch->name;
}
act("$N $t",vch,temp,ch,TO_CHAR);
}
return;
}
jlambert@atlas ~
$ gcc -Wall -ansi -std=c99 -c rompmote.c
I'm not exactly what is causing this error.
act_comm.c: In function void do_pmote(CHAR_DATA*, const char*):
act_comm.c:853: error: invalid conversion from const char* to char*
This is line 853.
if ( ( letter = strstr( argument, vch->name ) ) == NULL )
This is the whole function.