Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7805073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:06:23+00:00 2026-06-02T02:06:23+00:00

I am trying to read data from a very large binary file and process

  • 0

I am trying to read data from a very large binary file and process it using memory mapping, so it can be read byte by byte. I am getting a few compiler errors while doing this, and I can’t figure out what is causing them. I am doing this on a linux platform, for the record.

#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include<stdio.h>
#include<stdlib.h>
int fd;
char *data;

fd = open("data.bin", O_RDONLY);
pagesize = 4000;
data = mmap((caddr_t)0, pagesize, PROT_READ, MAP_SHARED, fd, pagesize);

The errors I get are as follows:

caddr not initialized

R_RDONLY not initialized

mmap has too few arguments.

I am using a Makefile to compile it, which looks like this:

all: order_book
CC = gcc 
CFLAGS = -std=c99

order_book: main.c
    $(CC) $(CFLAGS) -o order_book main.c
clean: 
    rm -f order_book

What am I doing wrong, and what can I do to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:06:24+00:00Added an answer on June 2, 2026 at 2:06 am

    Several errors, if this is indeed the entire piece of code that fails:

    1. O_RDONLY requires fcntl.h to be included.
    2. The code is defined outside of any function.
    3. The first argument to mmap is a void *, so just use NULL.
    4. pagesize is not declared.

    The following compiles:

    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/mman.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <fcntl.h>
    
    int fd;
    char *data;
    
    void main(int argc, char *argv[]) {
      fd = open("data.bin", O_RDONLY);
      int pagesize = 4000;
      data = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, pagesize);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read data from a binary file and put it into a
I am trying to read binary data from sys.stdin using Python 2.7 on Windows
I'm trying to read data from SQL Server database using Perl and the DBI
I am trying to read data from a file stream as shown below: fileStream.Read(byteArray,
I am trying to read data from a bluetooth barcode scanner (KDC300) using C.
I'm trying to read binary data from a specific offset. I write the data
I am trying to read data from a file, tokenize it and sort it,
im having some problems trying to read a SQlite data base from flash using
I am trying to read in data from a text file (the time). and
I'm getting something pretty strange going on when trying to read some data using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.