473,699 Members | 2,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why tthe header is not declared ?

HI~ EVERY ONE~ I have a small program here, when I tried to compile
it , it always reminds that
arrary.c: In function `main':
arrary.c:39: error: `header' undeclared (first use in this function)
arrary.c:39: error: (Each undeclared identifier is reported only once
arrary.c:39: error: for each function it appears in.)

Why is that ? I think I have declared it . :(

#include<stdlib .h>
#include<string .h>

typedef struct _HEADER {

short num1;
short num2;
short num3;
short num4;

}HEADER;

short i;

short x;
short y;
short z;
void readheader(HEAD ER *,FILE
*);-------------------------------------------THIS IS LINE 39
void writeheader(HEA DER *,FILE *);
main()

{

FILE *fp1;
FILE *fp2;

short ***datatable;

fp1=fopen("g.da t","r");
fp2=fopen("newd ata.dat","wb+") ;

readheader(head er,fp1);
writeheader(hea der,fp2);

for(x=0; x<2 ;x++){
for (y=0; y<3; y++){
for(z=0; z<4; z++){

fwrite(&datatab le[x][y][z],sizeof(short), 24,fp2);
fclose(fp1);
fclose(fp2);
}
}
}
}

void readheader(HEAD ER *header,FILE *fp1)
{
fread(&(header->num1),sizeof(s hort),1,fp1);
fread(&(header->num2),sizeof(s hort),1,fp1);
fread(&(header->num3),sizeof(s hort),1,fp1);
fread(&(header->num4),sizeof(s hort),1,fp1);
}

void writeheader(HEA DER *header,FILE *fp2)
{
fwrite(&(header->num1),sizeof(s hort),1,fp2);
fwrite(&(header->num2),sizeof(s hort),1,fp2);
fwrite(&(header->num3),sizeof(s hort),1,fp2);
fwrite(&(header->num4),sizeof(s hort),1,fp2);
}

Jul 20 '08 #1
30 1692
xiao wrote:
HI~ EVERY ONE~ I have a small program here, when I tried to compile
it , it always reminds that
arrary.c: In function `main':
arrary.c:39: error: `header' undeclared (first use in this function)
arrary.c:39: error: (Each undeclared identifier is reported only once
arrary.c:39: error: for each function it appears in.)

Why is that ? I think I have declared it . :(
Where?

--
Ian Collins.
Jul 20 '08 #2
xiao wrote:
HI~ EVERY ONE~ I have a small program here, when I tried to compile
it , it always reminds that
arrary.c: In function `main':
arrary.c:39: error: `header' undeclared (first use in this function)
Because you didn't declare it.
Why is that ? I think I have declared it . :(
Why would you think that? There isn't any line anywhere in your code
that looks remotely like a declaration of 'header'.
Jul 20 '08 #3
On Sat, 19 Jul 2008 19:10:37 -0700 (PDT), xiao <li*********@gm ail.com>
wrote:
>HI~ EVERY ONE~ I have a small program here, when I tried to compile
it , it always reminds that
arrary.c: In function `main':
arrary.c:39: error: `header' undeclared (first use in this function)
arrary.c:39: error: (Each undeclared identifier is reported only once
arrary.c:39: error: for each function it appears in.)

Why is that ? I think I have declared it . :(

#include<stdli b.h>
#include<strin g.h>

typedef struct _HEADER {

short num1;
short num2;
short num3;
short num4;

}HEADER;

short i;

short x;
short y;
short z;
void readheader(HEAD ER *,FILE
*);-------------------------------------------THIS IS LINE 39
void writeheader(HEA DER *,FILE *);
main()

{

FILE *fp1;
FILE *fp2;

short ***datatable;

fp1=fopen("g.d at","r");
fp2=fopen("new data.dat","wb+" );

readheader(hea der,fp1);
More than likely this is the actual line 39 since it is the first
place you use the token header. Where do you think you defined the
object this token should refer to?
>writeheader(he ader,fp2);

for(x=0; x<2 ;x++){
for (y=0; y<3; y++){
for(z=0; z<4; z++){

fwrite(&datata ble[x][y][z],sizeof(short), 24,fp2);
fclose(fp1);
fclose(fp2);
}
}
}
}

void readheader(HEAD ER *header,FILE *fp1)
While perfectly legal, reading and writing integers as binary data can
severely limit portability.
>{
fread(&(head er->num1),sizeof(s hort),1,fp1);
fread(&(head er->num2),sizeof(s hort),1,fp1);
fread(&(head er->num3),sizeof(s hort),1,fp1);
fread(&(head er->num4),sizeof(s hort),1,fp1);
}

void writeheader(HEA DER *header,FILE *fp2)
{
fwrite(&(heade r->num1),sizeof(s hort),1,fp2);
fwrite(&(heade r->num2),sizeof(s hort),1,fp2);
fwrite(&(heade r->num3),sizeof(s hort),1,fp2);
fwrite(&(heade r->num4),sizeof(s hort),1,fp2);
}

Remove del for email
Jul 20 '08 #4
On Jul 20, 10:04 am, Barry Schwarz <schwa...@dqel. comwrote:
<snip>
While perfectly legal, reading and writing integers as binary data can
severely limit portability.
I disagree, how does it harm portability? Portability is to be able to
compile the code in different systems. It's not to get the same
results in every system. Reading and writing the object representation
of integers in file streams does not harm in any way the programs
portability.
Jul 20 '08 #5
In article <08************ *************** *******@34g2000 hsf.googlegroup s.com>,
<vi******@gmail .comwrote:
>While perfectly legal, reading and writing integers as binary data can
severely limit portability.
>I disagree, how does it harm portability? Portability is to be able to
compile the code in different systems.
Don't be silly.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Jul 20 '08 #6
On Jul 20, 11:06 am, rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
In article <08543052-06c3-4240-9c9e-5be9f5750...@34 g2000hsf.google groups.com>,

<vipps...@gmail .comwrote:
While perfectly legal, reading and writing integers as binary data can
severely limit portability.
I disagree, how does it harm portability? Portability is to be able to
compile the code in different systems.

Don't be silly.

-- Richard
--
Please remember to mention me / in tapes you leave behind.

Thank you very much guys~~~ :)
Jul 20 '08 #7
vi******@gmail. com wrote:
On Jul 20, 10:04 am, Barry Schwarz <schwa...@dqel. comwrote:
<snip>
>While perfectly legal, reading and writing integers as binary data can
severely limit portability.

I disagree, how does it harm portability? Portability is to be able to
compile the code in different systems. It's not to get the same
results in every system. Reading and writing the object representation
of integers in file streams does not harm in any way the programs
portability.
The data files may not be portable between different implementations ,
even if the code is.

S
Jul 20 '08 #8
vi******@gmail. com said:
On Jul 20, 10:04 am, Barry Schwarz <schwa...@dqel. comwrote:
<snip>
>While perfectly legal, reading and writing integers as binary data can
severely limit portability.

I disagree, how does it harm portability? Portability is to be able to
compile the code in different systems.
That is *one* aspect of portability.
It's not to get the same results in every system.
Getting consistent results across platforms is another aspect of
portability, one that is sometimes important and sometimes not. To give an
example of a portable program where consistent results are not important,
consider an aleatoric music-writing program - as long as you're getting
the right *kind* of results, that's enough. For some tasks, however, such
inconsistency would not be acceptable. Portability of results /is/
important in many applications.
Reading and writing the object representation
of integers in file streams does not harm in any way the programs
portability.
It depends on what you mean by "portabilit y". It's a catch-all term that
means different things to different people. For example, in
comp.unix.progr ammer, it means "runs on ALL Unixes". :-) Sometimes, just
getting it to compile okay on the target system is *not* enough, and data
format portability is an important consideration. It is at such times that
good old-fashioned text files come into their own.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 20 '08 #9
On Sun, 20 Jul 2008 08:08:53 -0700 (PDT), vi******@gmail. com wrote:
>On Jul 20, 10:04 am, Barry Schwarz <schwa...@dqel. comwrote:
<snip>
>While perfectly legal, reading and writing integers as binary data can
severely limit portability.

I disagree, how does it harm portability? Portability is to be able to
compile the code in different systems. It's not to get the same
results in every system. Reading and writing the object representation
of integers in file streams does not harm in any way the programs
portability.
Compiling a program is not an end objective, it is one of a series of
steps taken to achieve an end objective. Part of that objective
should be for the code to work properly. Writing integer data in
binary on one system and trying to read it on another can lead to
problems with endian-ness (big vs little vs other), size (short need
not be two bytes) and representation (e.g., 1-complement,
2-complement, signed magnitude). It's even worse with floating point
data. Not all systems use IEEE; mine has three different
representations built into the hardware.

For data being transferred between systems using files, one simple way
to alleviate this problem is to put the data in the file as text. (OT:
for network transfers, there all those cute little system dependent
conversion functions which allow different systems to transfer/receive
the date in a network compliant format.)
Remove del for email
Jul 20 '08 #10

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

Similar topics

5
12569
by: Philipp | last post by:
Hello, I've got a class Lattice which is declared like that: // file: lattice.h class Lattice:public EventChooser{ public: Lattice(LatticeParameters* params); virtual ~Lattice(); // (...snip...)
11
2752
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do understand the objective. This example may represent an interface in need of a bit of refactoring, but it goes to demonstrate the basic idea as I understand it. http://developer.kde.org/documentation/library/cvs-api/kdevelop/html/ast_8h-source.html...
7
559
by: Roman Töngi | last post by:
When I declare a function prototype in a header-file, have I to include this header-file in the implemenation file? Example: //main #include "myfunction.h" int main() { myFunction(); return 0; }
6
1737
by: candy | last post by:
hi all, I just want to know that whether the C header files( like stdio.h,etc which the compiler provides) just contains the function declarations or they also contain some additionalinformation like where to look in the memory for the defintions of the standard functions like scanf(char*c,...)).
6
31487
by: Ravi | last post by:
Hi All: Is there any reason for declaring functions as static in a header file if that header file is going to be included in several other files? The compiler throws a warning for every such function declared but not called in the source file. Here is what I heard someone mention: The functions are declared static as an optimization. Making static "hidden-from-the-user" function to extern to appease -Wall compile argument is not a good...
8
3048
by: nrhayyal | last post by:
Hi c++ Gurus, Need your blessing. while testing few aspects with respect to header file inclusions, i observed few things which i would like to share with you. i have a file sqlca.h in which a structure sqlca is declared. i included this file as a soft link in /usr/include. the soft link is as follows: sqlca.h -> /usr/opt/db2_08_01/include64/sqlca.h
4
2038
by: Christoph Scholtes | last post by:
Hi, I have some questions about header files: Say I have a file functions.c which contains a couple of functions. I have declared some structs in this file too. The structs are defined in main.c. Now I create a header file which represents the interface of functions.c to my main program file main.c. I put in the header file: all function prototypes with keyword extern and the declarations of the structs, which are defined in the main...
16
2078
by: wdh3rd | last post by:
Hi everyone. I'm new to C and I have a few questions: I am making files for permutations and combinations. Files to be made are perm.c, perm.h, combo.c, and combo.h. Since both combinations and permutations use factorial to solve their problems, factorial is supposed to be in both perm.c and combo.c, and declared private. (1) You wouldn't ever put a prototype in a header if that function was
31
426
by: Madhur | last post by:
I have problems faced in adding definitions in the command header file. I have defined a header file which includes huge set of global constants and I am using them in all the C files. For example my sample.h file looks like this /************* File : sample.h
0
8704
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9187
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8936
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8894
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2361
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.