Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   about selection control (http://www.go4expert.com/forums/about-selection-control-t23920/)

pawan20 19Nov2010 12:18

about selection control
 
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();
}


jimblumberg 19Nov2010 12:23

Re: about selection control
 
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 19Nov2010 21:19

Re: about selection control
 
Just Code Tags is not good but also indent your code properly to make it better readable.

virxen 20Nov2010 02:17

Re: about selection control
 
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


All times are GMT +5.5. The time now is 12:29.