Pages: 1 [2]   Go Down
Author Topic: Searching string in char array  (Read 1159 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46266
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 58
Posts: 4036
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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 );
  }
  else
  {
    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.

Logged

Examples can be found in your IDE.

Pages: 1 [2]   Go Up
Jump to: