basic c question

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int age;
    char name[41];

    printf("please enter your age \n");
    scanf("%d", &age);
    printf("you are %d years old\n", age);

    if (!(age <= 19 && age >=13))
         printf("you are not a teenager\n");

    if (age > 19 || age < 13)
         printf("you are not a teenager\n");

    if  (age == 10 || 20 || 30 >=100)
        printf("you have a special age\n");


        printf("please enter your name: ");
        scanf("%s", name);

     if (strcmp(name, "bruce") != 0 && age != 40);   ///error on strcmp ??
        printf("your name is bruce, can i call you bruce\n");

    very_old = age > 80;

    if (!very_old)
        printf("you are not very old\n");
    }

hi there trying to teach myself c ive got an error in strcmp line i cant understand why its there could someone please help
thanks

ive got an error in strcmp

What are you trying to compile this on?

This is an arduino forum you know and that is code is not in a format that is suitable for an arduino.

What is the error?

hi mike
yes i understand just thought one needed to understand c first then start with the auduino its compiled on codeblocks

cheers

the error

C:\Users\jons\Desktop\Main file\c examples\Advance relation Operators\main.c|26|warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]|

You need a #include <string.h>

very_old isn't declared.

thank you got it going, is it ok to ask general c questions here, honestly i am obsesed with the 328

    if (strcmp(name, "bruce") != 0 && age != 40);  ///error on strcmp ??Should that semi-colon be there I wonder ........

if i take the semicolumb out it doesnt work
strangely in the example im working to it isnt there

With the semi-colon it should always execute the following printf.

If you leave the semi-colon there then it becomes the empty body of the if statement effectively disabling the test.

if (strcmp(name, "bruce"), age != 1 && age != 40)

ok panic off works now my statement as wrong, i missed an age out. ""bruce"), age" <--- here

thanks

You don't want a comma there. You want an || or &&

works now

I bet it doesn't

I bet it doesn't

i compiled that code after replacing

if (strcmp(name, "bruce") != 0 && age != 40);

with

if (strcmp(name, "bruce"), age != 1 && age != 40)

and, it is not showing any error message.

it is not showing any error message.

Just because something compile, it doesn't mean that it works properly.
Check what the comma operator does.

if (strcmp(name, "bruce"), age != 1 && age != 40)

here strcmp(name, "bruce ") is compared and output could be 0 or 1,
so if() is like

if(0, age != 1 && age != 40)

comma operator execute left to right so rightmost value is assigned to if statement , so instruction is actually converted into

if(age != 1 && age != 40)

so that it is not showing any error.

thank you for helping me ive read up on the commer

if (strcmp(name, "bruce") && age >= 13 && age <= 19)
printf("your name is bruce, you are the chosen one\n")

im still pulling my hair out trying to get this to work im thinking its something to do with the first %% the way i understand this works is if both strings compair result is 1 (boloon expression) and age is betweem 13 and 19, ive taken out the ! expression to make it a bit easer to understand

You might want to double check what "strcmp" returns - it may be counter-intuitive.

yup,
you have to use strcmp correctly

http://www.cplusplus.com/reference/cstring/strcmp/

this site is the place to be where you have to code C.