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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:40:50+00:00 2026-06-02T07:40:50+00:00

Im stuck when trying to write to my file within my subprogram. void new_page(float

  • 0

Im stuck when trying to write to my file within my subprogram.

void new_page(float *a, float *b, float *c, int *d){
    fprintf(results,"\nPage Totals: %f\t%f\t%f\t%d", *a,*b,*c,*d);
}

I get a warning saying

Warning: incompatible implicit declaration of built-in function 'fprinf' [enabled by default]

“error: ‘results’ undeclared (first use in this function)”

in main fprintf works fine, its just when it comes to the subprogram/function it wont work. from my understanding it thinks that results is undeclared, so do i have to pass the name or location of the file to make it work?

  • 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-02T07:40:52+00:00Added an answer on June 2, 2026 at 7:40 am

    Unless results is global, it is undefined.

    From the looks of it, you have opened a file (stream) as results in main. If so it only exists in the scope of main.

    Pass it along to the function. Do not recommend to make it global.


    It would look like:

    void new_page(FILE *results,  float *a, float *b, float *c, int *d){
        fprintf(results,"\nPage Totals: %f\t%f\t%f\t%d", *a,*b,*c,*d);
    }
    

    Also; if you have this function in a separate file then main(), where, as you say fprintf works – you have to include stdio.h in that file as well.


    Edit: Sounds like you are doing something wrong with that function signature and prototype etc.

    As a simple example (without needed checks on fopen etc):

    #include <stdio.h>
    
    void foo(FILE * fp)
    {
        fprintf(fp, "HELLO\n");
    }
    
    int main(void)
    {
        FILE *fp;
    
        fp = fopen("blabla", "w");
        foo(fp);
        fclose(fp);
    
        return 0;
    }
    

    Also; you say your compiler is not complaining. Are you using extensive warnings? If not you should. Ie GCC:

    $ gcc -Wall -Wextra -pedantic -o my_prog my_source.c

    I usually also add -std=c89, or if needed, -std=c99.

    Then run it wit valgrind:

    $ valgrind ./my_prog

    These two steps will give you lots of hints and clues to where things could be wrong.

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

Sidebar

Related Questions

I am stuck trying to write a rewrite rule for my htaccess file which
Really stuck on trying to write code to unzip a file or directory on
I am stuck trying to get this to write out the contents of the
I'm trying to write some code using posix threads but I'm stuck from the
I am new to php and trying to write a login function. Bit stuck
I'm kinda stuck with something which must be appalingly simple. I'm trying to write
Sometimes I still get stuck trying to translate procedural code into functional code. Is
I'm stuck trying to get a WinInet HTTP POST via SSL using ONLY C.
I'm stuck trying to get a regex to match a filetype in a sorting
I am trying to write merge sort and stuck here. What is the problem

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.