Computing.Net > Forums > Unix > Incompatible Pointer Type

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Incompatible Pointer Type

Reply to Message Icon

Name: Tina Brant
Date: February 12, 2004 at 10:37:00 Pacific
OS: windows98
CPU/Ram: 64k
Comment:

I could use some help. Can someone please tell me why my code gives the following error when compiled:

reverse.c:17:warning: passing arg1 of 'fscanf' from incompatible pointer type
reverse.c.17:warning: passing arg2 of 'fscanf' from incompatible pointer type

#include <stdio.h>

int main () {
FILE *f;
int count, i, tmp, *v;

/* open the file called "numbers" for reading */

f = fopen ("numbers", "r");
if (!f) {
fprintf (stderr, "hey!\n");
exit (1);
}

/* count the number of items in the file */

for (count=0; !feof (f); count++) fscanf ("%d", &tmp);
count--;

/* close the file */

fclose (f);

/* allocate space for an array called 'v' */

v = (int *) malloc (sizeof (int) * count);

/* open the file again for reading */

f = fopen ("numbers", "r");

/* read all the numbers into 'v' */

for (i=0; i<count; i++) fscanf (f, "%d", &v[i]);

/* close the file */

fclose (f);

/* print 'v' from last element to first element */

for (i=count-1; i>=0; i--) printf ("%d\n", v[i]);

exit (0);
}


I would appreciate your comments and suggestions. Thank you.



Sponsored Link
Ads by Google

Response Number 1
Name: thepubba
Date: February 12, 2004 at 16:17:24 Pacific
Reply:

Try making this change:

Yours: for (count=0; !feof (f); count++) fscanf ("%d", &tmp);

Mine: for (count=0; !feof (f); count++) fscanf (f,"%d", &tmp);

If you read up on fscanf, you will see that it expects the stream to be included. It is kind of hard to read the file if you don't tell the function where it is.


0

Response Number 2
Name: Tina Brant
Date: February 13, 2004 at 09:30:16 Pacific
Reply:

Jerry -- thank you for taking the time to respond. I will give it a try... :)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Incompatible Pointer Type

file.4.03 error compilation www.computing.net/answers/unix/file403-error-compilation/5512.html

unix Inodes www.computing.net/answers/unix/unix-inodes/4504.html

Can't compile Stevens code from apu www.computing.net/answers/unix/cant-compile-stevens-code-from-apu/5931.html