LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-23-2007, 01:29 PM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
fscanf error


hello, I hope someone can help me out as I'm a bit puzzeled by this warning, the warning is

warning: char format, different type arg (arg 3)

I get this from the following code

static int aseGetGEOMOBJECT(FILE *s)
{
char data[255];
int count=0;

rewind (s);
while (!feof (s))
{
fscanf(s, "%s", &data); THIS IS ERROR
if (!strcmp (data,"*GEOMOBJECT")) count++;
}

printf("number of objects %d\n",count);

return(count);

}

Thanks
 
Old 09-23-2007, 03:16 PM   #2
jdiggitydogg
Member
 
Registered: Sep 2007
Posts: 42

Rep: Reputation: 15
as you probably know, fscanf wants a character pointer for arg3, but you are passing it a pointer to a character pointer...so the compiler throws a warning.

just use 'data' and omit the '&'. in C, an array name by itself is an address (i.e. pointer) to the first element of the array. so in essense, '&data' is the address of the pointer. instead, you just want the pointer of itself. alternatively, you could do '&data[0]'.
 
Old 09-25-2007, 07:10 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
you are generally better off, IMHO,
for non-trivial programs, in reading the input as one string (fgets maybe)
and parsing it at leisure.
messing about with scanf is a pain.
 
  


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
C fscanf function exvor Programming 14 06-05-2007 09:40 AM
using fread with fscanf andystanfordjason Programming 4 12-20-2006 09:49 AM
fscanf returns -1 trutnev Programming 2 06-23-2005 08:50 AM
fscanf c programming tomato Programming 14 01-09-2004 08:33 PM
using fscanf function Linh Programming 2 07-14-2003 12:58 PM

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

All times are GMT -5. The time now is 01:43 PM.

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