what this warning means..

This is a discussion on what this warning means.. within the C Programming forums, part of the General Programming Boards category; i defined Code: char opt[254]; on this line i get |55|warning: char format, different type arg (arg 2)| Code: scanf("%s",&opt); ...

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    what this warning means..

    i defined
    Code:
    char opt[254];
    on this line i get
    |55|warning: char format, different type arg (arg 2)|
    Code:
    scanf("%s",&opt);
    what that means??

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    &opt is not a pointer to char, which you need for the %s format specifier. You should use a pointer to char (in this case, "opt").

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    and as a side note - you should limit a number of chars that could be read by the format - to prevent buffer overrun

    scanf("%253s",opt);
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    what will happen to the program if the user will enter 254 chars?

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Your head will twist right off your body, and zoom into outer space!!

    Try it and see.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,920
    The program will format your hard drive, too!
    http://apps.sourceforge.net/mediawik...Buffer_overrun
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. Dev-cpp - compiler options
    By tretton in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 06:20 PM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 07:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21