how to check specific word(char*) in char** words like "add" and do addtion by using if statement

StackOverflow https://stackoverflow.com/questions/22162706

  •  19-10-2022
  •  | 
  •  

سؤال

what I want to ask about is

something like this

char** words
int i =0;
while(words[i] != '\0'){
    if(words[i] == "add"){ 
        //do addition by previous value in words[i-1] and words[i-2] by atoi();

    }
} 

while I tried to solve this question, I used several different functions like strstr(), strcmp()

but I think I did some wrong about that

I need some smart person's help as soon as possible

لا يوجد حل صحيح

نصائح أخرى

This statement won't compare your strings, but addresses of variables. Pointer words[i] with "add" which is string literal of type char[].

 if(words[i] == "add")

use strcmp

  if(strcmp(words[i],"add")==0)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top