about selection control

pawan20's Avatar, Join Date: Nov 2010
Newbie Member
this code is not proper work.
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
char n[10],c[10];
clrscr();
printf("enter ur name=");
scanf("%s",n);
printf("enter ur city name=");
scanf("%s",c);

if(c=="agra")
printf("welcome");
else
printf("Bye-Bye");
getch();
}

Last edited by shabbir; 19Nov2010 at 21:18.. Reason: Code blocks
jimblumberg's Avatar
Ambitious contributor
First: Please use code tags!!!

Second: What is wrong with the program?

What exactly is wrong with it?

Does it compile without warnings/errors?

If not please post the exact error messages.

What do you expect the program to do?

What is it doing?

What are you entering when you run the program?

Jim
shabbir like this
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Just Code Tags is not good but also indent your code properly to make it better readable.
virxen's Avatar, Join Date: Nov 2009
Pro contributor
see the changes and comments

Code:
#include<stdio.h>
#include<conio.h>//compiler specific
#include<string.h>//add this library

int main(){//error 1 never void main always int main()
    char n[10],c[10];
    clrscr();//compiler specific
    printf("enter your name=");
    scanf("%s",n);getchar();//always after a scanf
    printf("enter your city name=");
    scanf("%s",c);getchar();//always after a scanf
    if(strcmp(c,"agra")==0)//corect way to compare 2strings. ==0 means 2 strings are equal
        printf("welcome");
    else
        printf("Bye-Bye");
    getch();//compiler specific
}
compiler specific means that it does not work in all compilers but only in few of them
shabbir like this