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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:34:38+00:00 2026-06-11T22:34:38+00:00

I have tried both strcat and strcat_s, but they both crash. Does anyone know

  • 0

I have tried both strcat and strcat_s, but they both crash. Does anyone know why this happens? I can’t find the problem.

Crash: "Unhandled exception at 0x58636D2A (msvcr110d.dll)"
_Dst        0x00ea6b30  "C:\\Users\\Ruben\\Documents\\School\\" char *
_SizeInBytes    260                         unsigned int
_Src        0x0032ef64  "CKV"                   const char *
available       228                         unsigned int
p           0x00ea6b50  ""                  char *

Code:

#include <Windows.h>
#include <strsafe.h>

extern "C"
{
    char* GetFilesInFolders(LPCWSTR filedir, char* path)
    {
        char* files = "";

        char DefChar = ' ';
        char* Streepje = "-";
        bool LastPoint = false;

        WIN32_FIND_DATA ffd;
        TCHAR szDir[MAX_PATH];
        HANDLE hFind = INVALID_HANDLE_VALUE;
        DWORD dwError = 0;

        StringCchCopy(szDir, MAX_PATH, filedir);
        hFind = FindFirstFile(szDir, &ffd);

        if (INVALID_HANDLE_VALUE == hFind) 
            return "";

        do
        {
            DWORD attributes = ffd.dwFileAttributes;
            LPCWSTR nm = ffd.cFileName;
            char name[260];
            WideCharToMultiByte(CP_ACP,0,ffd.cFileName,-1, name,260,&DefChar, NULL);

            for (int i = 0; i <= 260; i++)
            {
                if (name[i] == '.')
                    LastPoint = true;
                else if (name[i] == ' ')
                    break;
            }

            if (LastPoint == true)
            {
                LastPoint = false;
                continue;
            }

            if (attributes & FILE_ATTRIBUTE_HIDDEN)
            {
                continue;
            }
            else if (attributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                char* newfiledir = "";
                char* newpath = path;
                char* add = "\\";
                char* extra = "*";
                strcat_s(newpath, sizeof(name), name);
                strcat_s(newpath, sizeof(add), add);
                puts(newpath);
                strcpy_s(newfiledir, sizeof(newpath) + 1, newpath);
                strcat_s(newfiledir, sizeof(extra) + 1, extra);
                puts(newfiledir);

                size_t origsize = strlen(newfiledir) + 1;
                const size_t newsize = 100;
                size_t convertedChars = 0;
                wchar_t wcstring[newsize];
                mbstowcs_s(&convertedChars, wcstring, origsize, newfiledir, _TRUNCATE);
                LPCWSTR dir = wcstring;
                GetFilesInFolders(dir, newpath);
            }
            else
            {
                char* file = path;
                strcat_s(file, sizeof(name), name);
                puts(file);
                strcat_s(files, sizeof(file), file);
                strcat_s(files, sizeof(Streepje), Streepje);
                puts(files);
            }
        }
        while (FindNextFile(hFind, &ffd) != 0);

        FindClose(hFind);
        return files;
    }
}

int _tmain(int argc, _TCHAR* argv[])
{
    char* path = "C:\\Users\\Ruben\\Documents\\School\\";
    char* filedir = "C:\\Users\\Ruben\\Documents\\School\\*";
    size_t origsize = strlen(filedir) + 1;
    const size_t newsize = 100;
    size_t convertedChars = 0;
    wchar_t wcstring[newsize];
    mbstowcs_s(&convertedChars, wcstring, origsize, filedir, _TRUNCATE);
    LPCWSTR dir = wcstring;
    char* files = GetFilesInFolders(dir, path);
    return 0;
}

Extra info: I don’t want to use boost or strings and I want to keep this in unicode (default).

  • 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-11T22:34:40+00:00Added an answer on June 11, 2026 at 10:34 pm

    It looks like you don’t understand how variables are stored in memory or how pointers work. In your _tmain() you have char * path pointing to a constant string literal, which you pass into GetFilesInFolders(), where it gets modified. Compilers tend to allow char *s to point at constant strings for backward compatibility with old C programs. You cannot modify these. You cannot append to them. The compiler (generally) puts these in a read-only segment. That’s one reason why you’re getting an exception.

    Your whole GetFilesInFolders() is wrong. And as DarkFalcon pointed out, you haven’t allocated any space anywhere for files, you have it pointing to a constant string literal.

    Get “The C++ Programming Language” and read chapter 5.

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

Sidebar

Related Questions

I have tried this both on Ubuntu Linux and on Windows. I can not
Have tried to find solutions for this and can't really come up with anything.
I know I have done this before, but it isn't working today, nor can
I have tried both the below queries and they perform in same time. But
I have tried searching over the internet about this problem but not able to
I have tried many permutations but they all don't seems to work well. Am
I have a problem decoding HTML entities. I have tried using both System.Net.WebUtility.HtmlDecode() and
I have UITextView logView (tried both atomic and nonatomic ) and NSOperationQueue uploadQueue properties
I have tried setting a line-height for sIFR3 in both the sifr-config.js and my
I have tried this: #define format(f, ...) \ int size = strlen(f) + (sizeof((int[]){__VA_ARGS__})/sizeof(int))

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.