Go Down

Topic: Searching string in char array (Read 6019 times) previous topic - next topic


I'll write my own function and I'll take care of your suggestions about not using strings.

You WANT to use strings. You do NOT want to use Strings. There is a world of difference in that one little letter.
The art of getting good answers lies in asking good questions.


Squizza, time spent now just learning about C strings and string.h functions will save you a lot of time and headaches in future.

Here is a start point to build/experiment from:

Code: [Select]

// link to AVR LibC string.h library
// http://www.nongnu.org/avr-libc/user-manual/group__avr__string.html
#include <string.h>

char mywords[ 32 ];

void setup()
  Serial.begin( 9600 );

  strcpy( mywords, "Hello World" );
  Serial.println( mywords );

  char *substring;
  substring = strstr( mywords, "World" );
  if ( substring )
    Serial.println( substring );
    Serial.println( "World not found." );

void loop()

I would point you to the Arduino tutorials->examples page but some Idiot loaded a bunch of C++ String examples there -- maybe that's why so many new users think that C++ String objects are the way to go. Sure, you -can- use them if you don't do much but as a practice they are Bad for such small environments.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Go Up