LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-15-2006, 11:27 PM   #1
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Rep: Reputation: 35
sscanf


I have:
Code:
 const int BS = 128;
    // cmp stands for char tmp
    char buf[BS],
         cmp[BS];
    - - - -
    sscanf (buf, "VIDEO_DRIVER=%s", &cmp);
When compiling I get warning:
Quote:
src/settings.cpp:204: warning: char format, different type arg (arg 3)
What am I doing wrong? (App works ok)
Thanks.
 
Old 09-15-2006, 11:40 PM   #2
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
I think you want to get rid of that ampersand.

Code:
sscanf (buf, "VIDEO_DRIVER=%s", cmp);
 
Old 09-15-2006, 11:41 PM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
That should be
Code:
sscanf (buf, "VIDEO_DRIVER=%s", &cmp[0]);
, or simply
Code:
sscanf (buf, "VIDEO_DRIVER=%s", cmp);
 
Old 09-16-2006, 12:37 AM   #4
kornerr
Member
 
Registered: Dec 2004
Location: Russia, Siberia, Kemerovo
Distribution: Slackware
Posts: 893

Original Poster
Rep: Reputation: 35
Thanks, KenJackson, jlliagre.
 
Old 09-16-2006, 09:00 AM   #5
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
The gcc option -Wformat=0 can disable that warning. With -Wformat on gcc tests the syntax of printf and scanf.
If char cmp[256] is defined then the compiler treats "cmp" and "&cmp" the same. Try...
Code:
int main() {
    char buf[256];
    printf("%p = %p = %p\n", buf, &buf, &buf[0]);
    return 0;
}
PS: actually taking &buf in this example in my opinion is incorrect and confusing... though its allowed anyway by the compiler. I'd have to check if this is ANSI or not.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
atol sscanf question exvor Programming 1 12-04-2005 10:38 PM
another sscanf Q jnusa Programming 10 10-27-2004 02:33 AM
Garbage value dumped by sscanf sheenak Programming 2 05-27-2004 11:55 PM
sscanf help jpc82 Programming 8 11-04-2003 02:01 PM
glibc patch for sscanf.c jarin scott Linux - Software 2 08-03-2003 02:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration