473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

tmpnam, strcpy - incompatible pointer type?

Hey gang,

So I have my stdin which is user defined file, and am wanting to write
it to a temporary file (seems odd I know, but there is a sincere
reason), and then use that file as the stdin for the remaining part of
the program. I have combed the FAQ and got some preliminary questions
answered, and tried to model this after what I have seen suggested to
people previously, but for my strcpy and freopen I get,
"warning: passing arg 1 of `strcpy' from incompatible pointer type"
and
"warning: passing arg 1 of `freopen' from incompatible pointer type".
#include <stdio.h>
#include <string.h>
FILE *tempfile;
char s[L_tmpnam];
strcpy(tempfile, tmpnam(s));
/*tempfile = stdout; */
do{
. . .
for (i=0;i<istat;i++) floatarray[i] = (float) dfloatarray[i];
iostat = fwrite(floatarray,4,istat,tempfile);
if (iostat != istat) fprintf(stderr, "Failed on writing to temporary
file.");
} while(feof(stdin) == 0);
freopen(tempfile,"r",stdin);
But it doesn't have a problem w/ tempfile as arg 4 of fwrite? As you
can see, I have tried setting the tempfil as stdout, but that doesn't
change my error message. Any thoughts? Thanks as always!

JMW
Nov 14 '05 #1
1 2847
Josh Wilson wrote:
Hey gang,

So I have my stdin which is user defined file, and am wanting to write
it to a temporary file (seems odd I know, but there is a sincere
reason), and then use that file as the stdin for the remaining part of
the program. I have combed the FAQ and got some preliminary questions
answered, and tried to model this after what I have seen suggested to
people previously, but for my strcpy and freopen I get,
"warning: passing arg 1 of `strcpy' from incompatible pointer type"
and
"warning: passing arg 1 of `freopen' from incompatible pointer type".
#include <stdio.h>
#include <string.h>
FILE *tempfile;
char s[L_tmpnam];
strcpy(tempfile, tmpnam(s));
This line is evidence that you have no understanding
of what a FILE* is for.

A FILE* points to a piece of implementation magic
that somehow keeps track of an I/O stream. The details
of how this is done are none of your business; you are
not to look too closely at the magic. Meddle not in
the affairs of implementors, for they are subtle and
quick to undefined behavior.

The way you associate a FILE* stream with a given
file name is to use the fopen() function. You do *not*
try to blast the file name's characters onto the magical
object to which the FILE* points. Just Say No.
/*tempfile = stdout; */
do{
. . .
for (i=0;i<istat;i++) floatarray[i] = (float) dfloatarray[i];
iostat = fwrite(floatarray,4,istat,tempfile);
if (iostat != istat) fprintf(stderr, "Failed on writing to temporary
file.");
} while(feof(stdin) == 0);
freopen(tempfile,"r",stdin);
Repeat after me: A FILE* is not a file name. Write
this on the blackboard one hundred times, and then revisit
this line of code.
But it doesn't have a problem w/ tempfile as arg 4 of fwrite?
Why should it? fwrite() expects to receive a FILE* as
its fourth argument.
As you
can see, I have tried setting the tempfil as stdout, but that doesn't
change my error message. Any thoughts?


Thought: You really need to review C's I/O capabilities,
because the evidence suggests you don't yet understand them.
You are not yet ready to write this program.

--
Er*********@sun.com

Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Serve Laurijssen | last post by:
What's the difference between char buf; strcpy(buf, tmpnam(NULL)); and char buf; tmpnam(buf); According to my docs both calls write to an internal static buffer. What's
15
by: Chris Readle | last post by:
Hi all, Somewhat new to C and I'm getting the following error from my latest code. Here's the warning I'm getting: chris_readle_project3_assignment3.c: In function `main':...
3
by: kaizen | last post by:
Hi, i wrote the code in C and compiled in VC++ compiler. at that time it has thrown the below mentioned error. error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'...
55
by: Jake Thompson | last post by:
I need to copy a value into a char * field. I am currently doing this strcpy(cm8link.type,"13"); but I get an error of error C2664: 'strcpy' : cannot convert parameter 1 from 'const char'...
6
by: PraZ | last post by:
Hi all. Here is a simple code, which when compiled with gcc results in the warning "incompatible pointer type" for arg 1, as expected. But this is just what I want to do, because it makes it...
8
by: Michael | last post by:
Hi all, why do I get a message: warning: passing arg 1 of `collectInput' from incompatible pointer type In 'main' have: char inputString; collectInput(&inputString);
8
by: fei.liu | last post by:
I have the following source code. It seems wierd to me why gca's value cannot be reassigned. It's afterall a pointer and has a pointer value. I am aware that the standard says it's not allowed. But...
13
by: william | last post by:
code segment: long int * size; char entry; ............. size=&entry; ************************************* Gcc reported 'assignment of incompatible pointer type'.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.