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 746253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:04:10+00:00 2026-05-14T14:04:10+00:00

gcc 4.4.1 I am using the read function to read in a wave file.

  • 0

gcc 4.4.1

I am using the read function to read in a wave file. However, when it gets to the read function. Execution seems to stop and freezes. I am wondering if I am doing anything wrong with this.

The file size test-short.wave is: 514K.

What I am aiming for is to read the file into the memory buffer chunks at a time. Currently I just testing this.

Many thanks for any suggestions,

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
    char buff = malloc(10240);
    int32_t fd = 0;
    int32_t bytes_read = 0;

    char *filename = "test-short.wav";

    /* open wave file */
    if((fd = (open(filename, O_RDWR)) == -1))
    {
        fprintf(stderr, "open [ %s ]\n", strerror(errno));  
        return 1;
    }
    printf("Opened file [ %s ]\n", filename);
    printf("sizeof(buff) [ %d ]\n", sizeof(buff));

    bytes_read = read(fd, buff, sizeof(buff));

    printf("Bytes read [ %d ]\n", bytes_read);

    return 0;
}

=== Edit Corrections ===

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
    char buff[10240] = {0};
    int32_t fd = 0;
    int32_t bytes_read = 0;
    const char *filename = "test-short.wav";

    fd = open(filename, O_RDWR);
    if(fd == -1)
    {
    fprintf(stderr, "open [ %s ]\n", strerror(errno));
    return 1;
    }

    printf("sizeof(buff) [ %d ]\n", sizeof(buff));
    printf("strlen(buff) [ %d ]\n", strlen(buff));

    bytes_read = read(fd, buff, sizeof(buff));
    printf("Bytes read [ %d ]\n", bytes_read);

    return 0;
}
  • 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-05-14T14:04:11+00:00Added an answer on May 14, 2026 at 2:04 pm
    1. You assign pointer to the char, not char*.
    2. You read sizeof(char) (likely 1 byte), not 10240.
    3. You read the data into whatever buff, converted to pointer, points to, not into buff.
    4. The precedence issue mentioned by Ignacio Vazquez-Abrams is still relevant.
    5. You call strlen() on char, which doesn’t make much sense. Even less before populating what is supposed to be buffer.
    6. You assign const char * (string literal) to char*.

    Aren’t compiler warnings swarming around this code?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Cygwin with GCC, and ultimately I want to read in a file
I wanted to read the content of a file using the read() function. I
We can get the type returned by function in gcc using the typeof operator
running UNIX through putty, and using vi and gcc. I am attempting to read
Using GCC, how can I remove a symbol from a shared object after I've
I'm using gcc and OpenMPI . Usually I run MPI programs using the mpirun
I am using gcc -MM to generate prerequisites of dependencies rules for compiling source
I'm using GCC 4.3.3 on Ubuntu 9.04 64-bit and was getting errors using C++-style
I'm using gcc 4.3.2. I have the following code (simplified): #include <cstdlib> template<int SIZE>
I am using gcc/g++ to compile c/c++ applications - living on OpenSuSe btw. Is

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.