Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Simple imput/output program.

Options
  • 07-10-2009 3:25pm
    #1
    Registered Users Posts: 6,053 ✭✭✭


    #include<stdio.h>
    #include <conio.h>
    main()
    {

    char name ;
    char andy;

    printf( "please enter your name?");
    scanf( "%s", &name );
    if ( name == "andy" )
    printf("andys a cool name?") ;
    else
    printf("bet you wish your name was andy...\n");

    getch();

    }

    Error E2034 name2.c 10: Cannot convert 'char' to 'char *' in function main()

    Warning W8080 name2.c 17: 'andy' is declared but never used in function main()

    They are the errors that i get. What am i doing wrong in the code. I want to write a simple program that asks the user to imput a word, and then give a specific response based on what word they imput.

    thanks for any help:o


Comments

  • Registered Users Posts: 610 ✭✭✭nialo


    your trying to put multiple char's into a single char.

    you need to delcare a char array to take in the input.
    char chrData;
    char strData[100];
    
    printf(" Enter Single Character  :");
    scanf("%c",&chrData);
    
    printf(" Enter Multiple Characters (max 99) :");
    scanf("%s",strData);
    
    


  • Registered Users Posts: 2,534 ✭✭✭FruitLover


    Might be helpful to mention the language in the title in future, to save people guessing from the post...
    if ( name == "andy" )

    Another problem right here (once you've sorted out your string as pointed out above (caution: in a real application, you should make sure that no more than 99 chars get copied to the referenced memory location, rather than relying on the user not to input more than 99 chars!)). As the variable 'name' is effectively a pointer to a memory location, its value will not be equal to the string "andy". You'll need another way to compare the two strings...

    Also, your declaration of 'char andy' is superfluous.


Advertisement