Thread: Beginner scanf

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    1

    Beginner scanf

    Total beginner - I copied this code from the C For Dummies book into Xcode. The program runs ok but the editor comes up with a warning on the scanf line 'Format '%s' expects type 'char*', but argument 2 has type 'char(*)[20].' I haven't a clue what this means! Any help greatly appreciated.

    Code:
    #include <stdio.h>
    Code:
    
    int main() 
    {
        char me[20];
    
    
    printf("What is your name?\n");
        scanf("%s", &me);
    printf("Darn glad to meet you, %s!\n", me);
               
    return (0);
               
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    Remove the & from &me.

    If this is in your book, the book is broken.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner and scanf
    By Chleborad in forum C Programming
    Replies: 12
    Last Post: 02-17-2011, 01:11 AM
  2. Beginner question about scanf/printf
    By mickeyd in forum C Programming
    Replies: 6
    Last Post: 04-17-2010, 09:39 PM
  3. Simple Scanf question for beginner
    By somekid413 in forum C Programming
    Replies: 1
    Last Post: 12-15-2009, 04:56 PM
  4. Beginner Question: Problem with scanf and strings. Help!
    By lucidrave in forum C Programming
    Replies: 8
    Last Post: 08-11-2009, 10:22 PM
  5. Beginner question-scanf being weird
    By pernjuke in forum C Programming
    Replies: 5
    Last Post: 11-22-2006, 09:18 AM