2020-09-28 06:09 AM
hi
I want to locate a string in an other string and then mark its position with an 'X'. here is the code
#include "main.h"
#include "adc.h"
#include "dma.h"
#include "i2c.h"
#include "usart.h"
#include "gpio.h"
#include "stm32f1xx.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int position;
char Rcv[500];
char *ret;
ret=strstr(Rcv,"+CMTI");
position=ret-Rcv;
Rcv[position]='X';
the code doesn't run. when I comment the third line, it works. why is that?
Solved! Go to Solution.
2020-09-28 01:48 PM
2020-09-28 07:07 AM
The POSIX function strstr() already returns the first position of the substring, I see no need for your pointer fiddling.
The returned pointer can be NULL.
That is simple C stuff, which can easily be tested on the host.
The clib implementation of you embedded project might have limited POSIX compatibility.
2020-09-28 01:42 PM
dear Ozone
)
2020-09-28 01:48 PM
2020-09-28 10:13 PM
dear clive1
it worked! you are amazing as always!:folded_hands: