Thread: Unsure of Error, Beginner C

  1. #1
    Registered User
    Join Date
    May 2016
    Posts
    2

    Unsure of Error, Beginner C

    Hello All!
    I am attempting to learn C via "C Programming Absolute Beginner's Guide" and I am have an issue with one of the exercises and I cannot find or more likey understand my error. Below is the code and the "Build messages" I am receiving, also I am using Code::Blocks. Thank you for your time and help!

    Code:
    // Example program #1 from Chapter 6 of
    // Absolute Beginner's Guide to C, 3rd Edition
    //File Chapter6ex1.c
    
    
    //This program pairs three kids with their favorite superhero
    
    
    #include <stdio.h>
    #include <string.h>
    
    
    main()
    {
    
    
    char Kid1[12];
    // Kid1 can hold an 11-character name
    // Kid2 will be 7 characters (Maddie plus null 0)
    char Kid2[] = "Maddie";
    //Kid3 is also 7 characters, but specifically defined
    char Kid3[7] = "Andrew";
    // Hero1 will be 7 characters (adding null 0!)
    char Hero1 = "Batman";
    // Hero2 will have extra room just in case
    char Hero2[34] = "Spiderman";
    char Hero3[25];
    
    
        Kid1[0] = 'K'; //Kid1 is being defined character-by-character
        Kid1[1] = 'a'; //Not efficient, but it does work
        Kid1[2] = 't';
        Kid1[3] = 'i';
        Kid1[4] = 'e';
        Kid1[5] = '\0';  //Never forget the null 0 so C knows when the
                        //string ends
    
    
        strcpy(Hero3, "The Incredible Hulk");
    
    
        printf("%s\'s favorite hero is %s.\n", Kid1, Hero1);
        printf("%s\'s favorite hero is %s.\n", Kid2, Hero2);
        printf("%s\'s favorite hero is %s.\n", Kid3, Hero3);
    
    
        return 0;
    }
    
    // Example program #1 from Chapter 6 of
    // Absolute Beginner's Guide to C, 3rd Edition
    //File Chapter6ex1.c
    
    
    //This program pairs three kids with their favorite superhero
    
    
    #include <stdio.h>
    #include <string.h>
    
    
    main()
    {
    
    
    char Kid1[12];
    // Kid1 can hold an 11-character name
    // Kid2 will be 7 characters (Maddie plus null 0)
    char Kid2[] = "Maddie";
    //Kid3 is also 7 characters, but specifically defined
    char Kid3[7] = "Andrew";
    // Hero1 will be 7 characters (adding null 0!)
    char Hero1 = "Batman";
    // Hero2 will have extra room just in case
    char Hero2[34] = "Spiderman";
    char Hero3[25];
    
    
        Kid1[0] = 'K'; //Kid1 is being defined character-by-character
        Kid1[1] = 'a'; //Not efficient, but it does work
        Kid1[2] = 't';
        Kid1[3] = 'i';
        Kid1[4] = 'e';
        Kid1[5] = '\0';  //Never forget the null 0 so C knows when the
                        //string ends
    
    
        strcpy(Hero3, "The Incredible Hulk");
    
    
        printf("%s\'s favorite hero is %s.\n", Kid1, Hero1);
        printf("%s\'s favorite hero is %s.\n", Kid2, Hero2);
        printf("%s\'s favorite hero is %s.\n", Kid3, Hero3);
    
    
        return 0;
    }
    Build Messages

    Line 20: "warning: initialization makes integer from pointer without a cast [enabled by default]"
    Line 35: "warning: format '%s' expects argument of type 'char *', but argument has tupe 'int' [-Wformat=]"

    I really appreciate the help,
    Jonathan

    P.S. If you do have the same book I do, its Chapter 6 Exercise 1 on page 55 on my edition.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Code:
    char Hero1[] = "Batman";  // needs the brackets here!

  3. #3
    Registered User
    Join Date
    May 2016
    Posts
    2
    Thanks for the help algorism, there was an error in the text I am using and more disappointingly I missed the error in my code. Lesson learned! Thanks again!

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,106
    Quote Originally Posted by Pushpop View Post
    Thanks for the help algorism, there was an error in the text I am using and more disappointingly I missed the error in my code. Lesson learned! Thanks again!
    Look in the book for the address of the website to download the "Errata List", probably at the publishers website. There usually is one for all technical books, C Programming and others. That should list that error and others that escaped the authors and reviewers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unsure why I'm getting this error
    By pepperlizard in forum C++ Programming
    Replies: 6
    Last Post: 11-30-2012, 04:03 PM
  2. Replies: 2
    Last Post: 01-11-2010, 02:00 PM
  3. Unsure how to fix this error
    By SniperSAS in forum Game Programming
    Replies: 5
    Last Post: 08-21-2005, 04:46 PM
  4. unsure
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 08-13-2002, 09:37 AM
  5. Little Unsure?
    By kas2002 in forum C Programming
    Replies: 8
    Last Post: 06-12-2002, 08:18 PM

Tags for this Thread