Thread: I'm very new to C-Programming..Help me with my mistake..

  1. #1
    Registered User Koka.Udbhav's Avatar
    Join Date
    Aug 2016
    Location
    India/Hyderabad
    Posts
    2

    Exclamation I'm very new to C-Programming..Help me with my mistake..

    Code:
    #include<stdio.h>
    #include<conio.h>
    int main()
    {
        
        char name = Udbhav;
        
        printf("What is your name? \n");
        
        scanf("%c",&name);
        if( name = Udbhav)
        {
            Printf("You are owner of this computer \n" );
            }else{
            Printf("You're not the owner of this computer");      
            }     
                  
                  
        getch();
        return 0;          
                  
        }
    Need help can i know what is the mistake??

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Do you have a compiler and a debugger? Execute the code
    and you will see various errors.

    A few things I will say:

    >char name = Udbhav;

    A character string like this can only be pointer-type.
    What you assign to the address must be in the form of a string literal.

    >Printf

    C is case-sensitive. printf is always lower-case.

    > if( name = Udbhav)

    Learn about the differences between assignment and equality
    operators. There is an excellent tutorial on this site for that.

    There are other errors too, but this is a start.

    Good luck and welcome to cboard and C!
    Double Helix STL

  3. #3
    Registered User Koka.Udbhav's Avatar
    Join Date
    Aug 2016
    Location
    India/Hyderabad
    Posts
    2

    Talking

    Quote Originally Posted by swgh View Post
    Do you have a compiler and a debugger? Execute the code
    and you will see various errors.

    A few things I will say:

    >char name = Udbhav;

    A character string like this can only be pointer-type.
    What you assign to the address must be in the form of a string literal.

    >Printf

    C is case-sensitive. printf is always lower-case.

    > if( name = Udbhav)

    Learn about the differences between assignment and equality
    operators. There is an excellent tutorial on this site for that.

    There are other errors too, but this is a start.

    Good luck and welcome to cboard and C!
    Thanks and can you please fix the errors and send me the code back in PM?
    So,I can learn from that..

    Do you have a compiler and a debugger?
    Yes,I'm using DevC++

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Koka.Udbhav View Post
    Thanks and can you please fix the errors and send me the code back in PM?
    So,I can learn from that
    This forum is not a homework completion service. Fix it yourself. swgh told you exactly what to do.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Just to echo what Elkvis said, if you post the code you have modified,
    with any other errors etc people can give you advice on how to amend
    them etc.
    Double Helix STL

  6. #6
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Also, please do not use conio.h. This header file provides functions for Windows only, and is not portable to Linux or other systems.

    It makes it impossible for many of us to compile your code to test.

  7. #7
    Registered User
    Join Date
    Aug 2016
    Posts
    4
    There is a Lot of mistakes in your program,Try this one,i have made some modifications.

    Code:
        
       main()
      {
        char name[]="udbhav",name2[100];
     printf("What is your name? \n");
    
        scanf("%s",&name2);
        if( strcmp(name,name2)==0)
        {
            Printf("You are owner of this computer \n" );
            }else{
            Printf("You're not the owner of this computer");      
            }     
    
    
        getch();
       }
    1.You have to be thorough in Strings concept(how to declare,define)
    It is explained in this website
    here the link C Strings - Cprogramming.com
    2.Practice using String Library Functions.

    All the best.!!

  8. #8
    Registered User
    Join Date
    Sep 2016
    Posts
    4
    Character constant cannot be more than one character long,its better if you learn about basic of defining character constant.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's the mistake i'v did in this?
    By karthikslegend in forum C++ Programming
    Replies: 13
    Last Post: 06-25-2013, 12:15 PM
  2. what is my mistake
    By Dave Couture in forum C Programming
    Replies: 8
    Last Post: 08-14-2012, 10:28 PM
  3. mistake of using awk
    By lehe in forum Linux Programming
    Replies: 6
    Last Post: 04-02-2009, 04:41 PM
  4. a mistake in the c programming language book.wtf?
    By KidMan in forum C Programming
    Replies: 9
    Last Post: 01-17-2006, 04:33 AM

Tags for this Thread