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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Simple imput/output program.

  • 07-10-2009 2:25pm
    #1
    Registered Users, Registered Users 2 Posts: 6,054 ✭✭✭


    #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, Registered Users 2 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, Registered Users 2 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