strings in mplab

Read up on all the shortcuts and quick workarounds for our development tools

strings in mplab

Postby Entropy » Wed Sep 30, 2015 3:01 pm

I have more of C+ problem then an actual pic problem. What I want is to read a string (oi) letter by letter and if it encounter a specific letter then execute a specific function. I try those ifs even with == and = nothing work so far, I even change oi to "123" and function S(); and function O(); are still executed.

Code: Select all
char oi[] = "123";

if (oi!="") {
        stringLength = strlen(oi);
        for(i = 0; i < stringLength; ++i){
            if (oi[i]="s"){S();}
            if (oi[i]="o"){O();}
            else linie();
        }
        strcpy(oi,"");


I suspect is the string, I read it wrong or something like that, where is the line if (oi[i]="s"){S();} mplab says warning: (358) illegal conversion of pointer to integer
Entropy
 
Posts: 24
Joined: Fri Sep 04, 2015 7:04 am
Location: Timisoara, Romania

Re: strings in mplab

Postby jtemples » Wed Sep 30, 2015 6:18 pm

I would suggest reading some basic C tutorials first.

"=" is the assignment operator, "==" is the comparison operator. "s" is a string, 's' is a character.

You can't compare or assign strings with the == and = operators.

And don't reinvent the C library.

Code: Select all
if (strchr(oi, 's') { S(); }
jtemples
Verified identity
 
Posts: 162
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: strings in mplab

Postby Entropy » Wed Sep 30, 2015 7:03 pm

jtemples wrote:And don't reinvent the C library.

I wont

Thanks for the code, now my program is working.
Entropy
 
Posts: 24
Joined: Fri Sep 04, 2015 7:04 am
Location: Timisoara, Romania

Re: strings in mplab

Postby ric » Wed Sep 30, 2015 11:35 pm

I have just moved this topic from "Test posts" to "Tips and Tricks", because posts in the test forum are automatically deleted after a couple of days.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 398
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products


Return to Tips and Tricks

Who is online

Users browsing this forum: No registered users and 1 guest