Ok. so I'm writing up the below assignment and have a little snag in the code
• takes command line arguments of one string and two single characters
• locates the first character in the string: if the character was located at position i, then the character at position (i+2) of the string is changed to be the second input character. This operation is repeated until all the sought character occurrences have been found and changed.
For example, here would be some sample runs of the program:
/home/you> lab13q1 gbc g Y
Modified string is: gbY

/home/you> lab13q1 "abc deaf hiaklar" a X
Modified string is: abX deafXhiakXar

the "abc deaf hjaklar" doesn't work propery cause it's trying to read after the string has ended. I tried putting if statement that will print "wtf" once reaches null but it's not working. I'm justt getting 3 XXX at the end of the 2nd example. How do I correct it? Thanks.



Code:
#include <stdio.h>
#include <string.h>

int main (int argc, char *argv[]) {
char *str = argv[1], value1 = *argv[2], value2 = *argv[3], *temp;
temp = str;
while ((temp = strchr(temp, value1)) != NULL) {
if ((temp + 2) != NULL) {
*(temp + 2) = value2;
temp++;
}
else
printf ("wtf");
 }