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

  • Home
  • SEARCH
  • 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 7817831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:22:30+00:00 2026-06-02T06:22:30+00:00

I’ve never had so much trouble writing data to files! I’m running GCC from

  • 0

I’ve never had so much trouble writing data to files! I’m running GCC from MinGW, because I’m used to using GCC in Linux. I usually use the Linux system calls open(), write(), and read(), but I’m writing a Windows program now and I had trouble using read()/write() in Windows, so I’m just using the standard libraries. Anyway, the problem I’m having is I have no idea how to write to a file! I’ve defined “FILE *” variables, used fopen(), with “r+b”, “wb”, and “w+b”, but I still cannot write to my output file with fwrite() or fprintf(). I don’t know what I’m even doing wrong! Here’s my source:

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

#define DEBUG   1

/*** Global functions ***/
double  highfreq(double deg);

/*** Global variables ***/
double  sin_now;

unsigned int    *ptr;
unsigned char   *key,   *infilename,    *outfilename;
FILE    *infile,    *outfile,   *keyfile;

const char  *pipe_name="[pipe]";

int main(int argc, char *argv[]) {
    unsigned int    x,  y,  z;

    if(argc!=3) {
        fprintf(stderr, "Syntax error: %s <infile.txt> <outfile.wav>", argv[0]);
        return 1;
    }
    if(argv[1][0]=='-') {
        infile=stdin;
        infilename=(unsigned char *)pipe_name;
    }
    else {
        infilename=argv[1];
        if((infile=fopen(infilename, "rb"))==NULL) {
            fprintf(stderr, "Could not open input file for modulation.\n", infile);
            return 2;
        }
    }
    if(argv[2][0]=='-') {
        outfile=stdout;
        outfilename=(unsigned char *)pipe_name;
    }
    else {
        outfilename=argv[2];
        if((infile=fopen(outfilename, "wb"))==NULL) {
            fprintf(stderr, "Could not open/create output file for modulation.\n", outfile);
            return 3;
        }
    }
    if(DEBUG) printf("Input file:\t%s\nOutput file:\t%s\n", infilename, outfilename);

    fprintf(outfile, "Why won't this work!?\n");

    fclose(infile);
    fclose(outfile);
    return 0;
}

double highfreq(double deg) {
    double  conv,   rad;

    conv=M_PI/180;
    rad=deg*conv;
    return sin(rad);
}

I’m eventually going to make a WAV file as output, hence the “highfreq()” function, but for now I can’t even get it to write to a file! fprintf() returns with an error value of -1, if that helps anyone. I don’t really understand, though because from what I read, this simply indicates there was an error, but nothing more.

  • 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-02T06:22:31+00:00Added an answer on June 2, 2026 at 6:22 am
        outfilename=argv[2];
        if((infile=fopen(outfilename, "wb"))==NULL) {
    

    That’s the second time in your code you assign the result of fopen to infile. You probably wanted outfile there.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am currently running into a problem where an element is coming back from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

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.