473,785 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

test.c:24: error: `read' undeclared (first use this function)

Hello,
when I try to compile the following code:
/* This fragment of code is taken from an online tutorial */
#include<stdio. h>
#include<fcntl. h>
#include<stdlib .h>

float bigbuff[1000];

main(int argc, char **argv)

{ int fd;
int bytes_read;
int file_length;

if ( (fd = open(argv[1],O_RDONLY)) = -1)
{ /* error file not open */
perror("Datafil e");
exit(1);
}
if ( (bytes_read = read(fd,&file_l ength,
sizeof(int))) == -1)
{ /* error reading file */
exit(1);
}
if ( file_length > 999 ) {/* file too big */ }
if ( (bytes_read = read(fd,bigbuff ,
file_length*siz eof(float))) == -1)
{ /* error reading open */
exit(1);
}
}
I get this error message:

test.c: In function `int main(int, char**)':
test.c:24: error: `read' undeclared (first use this function)
test.c:24: error: (Each undeclared identifier is reported only once for
each function it appears in.)
I have seen, that the function read() isn´t defined in <stdio.h>. Does
anybody can help me? Do you know, if there is defined a function read()
anywhere with the prototype
"int read(int handle, char *buffer, unsigned length)"
and can tell me.

Thanks a lot, if you could help me.

Peter
Dec 9 '05 #1
4 22959
Peter Rothenbuecher wrote:
Hello,
when I try to compile the following code:
/* This fragment of code is taken from an online tutorial */
[...]
I get this error message:

test.c: In function `int main(int, char**)':
test.c:24: error: `read' undeclared (first use this function)
test.c:24: error: (Each undeclared identifier is reported only once for
each function it appears in.)
I have seen, that the function read() isn´t defined in <stdio.h>. Does
anybody can help me? Do you know, if there is defined a function read()
anywhere with the prototype
"int read(int handle, char *buffer, unsigned length)"
and can tell me.


There is no function 'read' in Standard C++. It is platform-specific,
and your particular implementation may not even have it. You might want
to read about stream-based file handling (FILE* and 'fXXXX' functions
instead of 'XXXX' ones), those _are_ standard.

V
Dec 9 '05 #2
Victor Bazarov wrote:
Peter Rothenbuecher wrote:
Hello,
when I try to compile the following code:
/* This fragment of code is taken from an online tutorial */
> [...]
I get this error message:

test.c: In function `int main(int, char**)':
test.c:24: error: `read' undeclared (first use this function)
test.c:24: error: (Each undeclared identifier is reported only once for
each function it appears in.)
I have seen, that the function read() isn´t defined in <stdio.h>. Does
anybody can help me? Do you know, if there is defined a function read()
anywhere with the prototype
"int read(int handle, char *buffer, unsigned length)"
and can tell me.


There is no function 'read' in Standard C++. It is platform-specific,
and your particular implementation may not even have it. You might want
to read about stream-based file handling (FILE* and 'fXXXX' functions
instead of 'XXXX' ones), those _are_ standard.


Or iostreams, which are also standard:

http://www.parashift.com/c++-faq-lit....html#faq-15.1

Cheers! --M

Dec 9 '05 #3
mlimber wrote:
Victor Bazarov wrote:
Peter Rothenbuecher wrote:
Hello,
when I try to compile the following code:
/* This fragment of code is taken from an online tutorial */

> [...]

I get this error message:

test.c: In function `int main(int, char**)':
test.c:24: error: `read' undeclared (first use this function)
test.c:24: error: (Each undeclared identifier is reported only once for
each function it appears in.)
I have seen, that the function read() isn´t defined in <stdio.h>. Does
anybody can help me? Do you know, if there is defined a function read()
anywhere with the prototype
"int read(int handle, char *buffer, unsigned length)"
and can tell me.


There is no function 'read' in Standard C++. It is platform-specific,
and your particular implementation may not even have it. You might want
to read about stream-based file handling (FILE* and 'fXXXX' functions
instead of 'XXXX' ones), those _are_ standard.

Or iostreams, which are also standard:

http://www.parashift.com/c++-faq-lit....html#faq-15.1

Cheers! --M

Ok, thanks.
Peter
Dec 9 '05 #4
Peter Rothenbuecher wrote:
Hello,
when I try to compile the following code:
/* This fragment of code is taken from an online tutorial */
#include<stdio. h>
#include<fcntl. h>
#include<stdlib .h>

float bigbuff[1000];

main(int argc, char **argv)

{ int fd;
int bytes_read;
int file_length;

if ( (fd = open(argv[1],O_RDONLY)) = -1)
{ /* error file not open */
perror("Datafil e");
exit(1);
}
if ( (bytes_read = read(fd,&file_l ength,
sizeof(int))) == -1)
{ /* error reading file */
exit(1);
}
if ( file_length > 999 ) {/* file too big */ }
if ( (bytes_read = read(fd,bigbuff ,
file_length*siz eof(float))) == -1)
{ /* error reading open */
exit(1);
}
}
I get this error message:

test.c: In function `int main(int, char**)':
test.c:24: error: `read' undeclared (first use this function)
test.c:24: error: (Each undeclared identifier is reported only once for
each function it appears in.)
I have seen, that the function read() isn´t defined in <stdio.h>. Does
anybody can help me? Do you know, if there is defined a function read()
anywhere with the prototype
"int read(int handle, char *buffer, unsigned length)"
and can tell me.

Thanks a lot, if you could help me.

Peter


read() is non-stdandard.

In Windows, include <io.h> and <fcntl.h> -and- the function
name is "_read()". Check your compiler's on-line docs.

In unix/linux (usually), include <unistd.h> -and- the function
name is "read()". Check your compiler's 'man pages'.

Larry
Dec 10 '05 #5

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

Similar topics

0
1925
by: Lorenz Köhl | last post by:
hi, I've python 2.3 and apache 2.0.47 installed on my SuSE8.2. when trying to compile modpython into apache, make stops with the error ---- In file included from /usr/local/include/python2.3/Python.h:8, from /home/software/network/apache/mod_python-3.0.3/src/include/mod_python.h:92, from requestobject.c:64: /usr/local/include/python2.3/pyconfig.h:844:1: warning: "_POSIX_C_SOURCE" redefined
3
4157
by: Victor | last post by:
I'm trying to run this java program, but somehow the program always quit w/o giving any error msg at all. it happenned inside the first case statements. Strangely, after printing happen2, it just stopped, and I had no idea what happens. another error is on the last function. I have already declared plane as M x N array, but it keeps giving error like hwone.cpp(50) : warning C4101: 'plane' : unreferenced local variable hwone.cpp(212) :...
0
1665
by: Zach | last post by:
Using Dev-C++ 4.9.8.5 I get error: Compiler: Default compiler Executing g++.exe... g++.exe "C:\winroot\src\c++\stupid_tricks\functor_trick.cpp" -o "C:\winroot\src\c++\stupid_tricks\functor_trick.exe" -I"C:\DEV-CPP\include\c++" -I"C:\DEV-CPP\include\c++\mingw32" -I"C:\DEV-CPP\include\c++\backward" -I"C:\DEV-CPP\include" -L"C:\DEV-CPP\lib" C:/winroot/src/c++/stupid_tricks/functor_trick.cpp: In member function
8
5087
by: Equilibrium | last post by:
what did I wrong with the program ? (use VC++) /* Using if statment, relational operators, and equality operators */ #include<stdio.h> int main() { printf("Enter two integers, and I will tell you\n"); printf("the relationships they satisfy: ");
5
5682
by: cranium.2003 | last post by:
hi, Here is my code #include <iostream.h> int main() { cout <<"HI"; return 0; } and using following command to compile a C++ program g++ ex1.cpp -o ex1
4
1961
by: Jon Rea | last post by:
I have the following code that works on Visual C++ 2005 and on GCC. bool VectorContains( const std::vector<int>& vect, int value ) { std::vector<int>::const_iterator iter; for( iter = vect.begin(); iter != vect.end(); iter++ ) { if( *iter == value ) { return true;
1
2073
by: jrefran | last post by:
Hi everyone! I have problem on my DBD:Oracle installation from source code. Does anyone familiar with this kind of error. Please help! I'm completely new with this kind of work item. This is the error during execution of "make". This error was in the last part. ---------------------------------- /usr/local/lib/perl5/5.8.8/sun4-solaris/CORE/proto.h:2089: warning: `__malloc__' attribute dir ective ignored...
13
4741
by: problem. | last post by:
#include <stdio.h> #include <stdlib.h> int main(void) { int a, b; float result = 0.0f; char symbol = '\0'; int loop = 0;
7
70314
by: singhPrabhat | last post by:
Hi, I am using gcc (GCC) 4.2.1 (SUSE Linux). SUSE 10.3 While compiling a .c file I get following error :::: CCWebConfiguration.h:70: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’ CCWebBrowser.c: In function ‘main’:
0
9489
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
10356
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...
0
10162
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10100
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,...
1
7509
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
6744
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();...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4061
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
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.