mardi 10 novembre 2015

if statements in c with characters [duplicate]

This question already has an answer here:

I am trying to get make a C program where I put a command line argument in. If that command line argument is graphics (i.e. ./a.out graphics) I should get an output:

You have chosen graphics

Otherwise I should get an output saying:

This is not graphics

The program is below:

#include <stdio.h>
#include <strings.h>

int main(int argC,char **argV)
{
    char type[30];
    sscanf(argV[1],"%s",&type);
    printf("Type is %s\n",type);
    if (type=="graphics")
    {
        printf("You have chosen graphics\n");
    }
    else
    {
        printf("This is not graphics\n");
    }
}

How do I tweak this program to get desired output?

Thank you for your time.

Aucun commentaire:

Enregistrer un commentaire