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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:40:37+00:00 2026-05-31T09:40:37+00:00

I am trying to save some files using C, with this code: sprintf(playerinput,%s,end); sprintf(fileloc,%s/.notend,getenv(HOME));

  • 0

I am trying to save some files using C, with this code:

sprintf(playerinput,"%s",end);
sprintf(fileloc,"%s/.notend",getenv("HOME"));
playerdata = fopen(fileloc, "w+"); /*create the new file*/
if (!playerdata)
{
printf("\n\t\t\tCould not save settings file.");    
return;
} else {
fputs(playerinput,playerdata); 
fclose(playerdata); 
}

It should set playerinput to the end variable, which works on Linux, then set the file location to the homearea/.notend, then make or edit the file, and put it out. In Linux (gcc), this works fine. The same code, however, on Windows (i586-mingw32msvc-gcc, does not work. Am I doing something wrong, or is another header file needed? Currently I have:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>   
#include <string.h>
#include <stdlib.h>
#define MAX_NOTES 200
#define MAX_NAMES_TEXT 200
#define MAX_NOTES_TEXT 2000

as my headers and defines. If you need more information, just ask.

  • 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-31T09:40:39+00:00Added an answer on May 31, 2026 at 9:40 am

    The environment variable HOME is not a default environment variable on Windows so:

    getenv("HOME");
    

    will return NULL. You need to use a different function to obtain a user’s home directory on Windows, SHGetFolderPath will provide this:

    char path[MAX_PATH + 1] = "";
    
    if (SUCCEEDED(SHGetFolderPath(0, 
                                  CSIDL_LOCAL_APPDATA,
                                  0,
                                  SHGFP_TYPE_CURRENT,
                                  path)))
    {
        std::cout << path << "\n";
    }
    

    This output:

    C:\Documents and Settings\admin\Local Settings\Application Data

    on my machine.

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

Sidebar

Related Questions

I am trying to load multiple files using HTML5. This is my code I
I'm trying to save some UserControl-Infos into a List like this: List<UserControlDetails> myList; public
How can I access this element: <input type=submit value=Save as XML onclick=some code goes
I'm trying to save some lookup table data out to a YAML file so
I'm trying to save some XML-Data in my UserSettings (Properties.Settings.Default.UserSettings) in a .NET Winforms
I'm trying to save some layouts from DevExpress Grid Controls so that users can
Hi I am trying to use NSUserDefaults to save some default values in database.
I'm trying to create core data application. Some times when trying to save data,
I'm trying to parse a MIME-Message, using SharpMimeTools and some sample Mime Messages from
I'm trying to do some work between java and r (using some of the

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.