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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:17:08+00:00 2026-05-13T06:17:08+00:00

— All of the revised code still refuses to run well, please help —

  • 0

— All of the revised code still refuses to run well, please help —

When I compile my code in Windows, I get memory errors. However on the Mac, where I initially coded this code, it works fine. I need to get this working on Windows.

It’s something to do with the way I handle my char strings using strcpy that the Mac seems to be fine with (I guess it’s related to gcc vs. Microsoft’s way of doing things).


Here’s the code for the complainers:
main.cpp

#include "Cust.h"
using namespace std;

int main (int argc, char * const argv[]) {
    Cust customers[500];
    char tmpString[70] = " ";
    char * pch = new char[255];
    string tmpAcctFN = " ";
    string tmpAcctLN = " ";
    ifstream input("P3_custData.txt");
    for (int idx = 0; idx < 130; idx++){
        input.getline(tmpString, 70, '\n');
        strcpy(pch,strtok(tmpString," "),255);
        customers[idx].setAcctNum(pch);
        cout << pch << endl;
        strcpy(pch, strtok(NULL," "));;
        customers[idx].setAcctFN(pch);
        cout << pch << endl;
        strcpy(pch, strtok(NULL," "));;
        customers[idx].setAcctLN(pch);
        cout << pch << endl;
        strcpy(pch, strtok(NULL," "));;
        customers[idx].setCurrBalance(atol(pch));
        cout << pch << endl;
        strcpy(pch, strtok(NULL," "));;
        customers[idx].setPIN(atoi(pch));
        cout << pch << endl;
    }
    input.close();
    return 0;
}

Cust.h

/*
 *  Cust.h
 *  Project 3
 *
 *  Created by Anthony Glyadchenko on 11/17/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */
#include <iostream>
#include <string>

using namespace std;

#ifndef CUST_H
#define CUST_H

class Cust{
public:
    char * getAcctNum();
    void setAcctNum(char num[]);
    double getCurrBalance();
    void setCurrBalance(double balance);
    void addToCurrBalance(double amount);
    void subFromCurrBalance(double amount);
    void setAcctFN(char firstName[]);
    void setAcctLN(char lastName[]);
    char * getAcctFN();
    char * getAcctLN();
    void setPIN(int pin);
    int getPIN();

private:
    char acctNum[255];
    char acctFN[255];
    char acctLN[255];
    double currBalance;
    int pin;
    char fileName[255];
};
#endif

Cust.cpp

/*
 *  Cust.cpp
 *  Project 3
 *
 *  Created by Anthony Glyadchenko on 11/17/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */
#include <fstream>
#include <string>
#include <sstream>
#include "Cust.h"

using namespace std;

char * Cust::getAcctNum(){
    return acctNum;
}

void Cust::setAcctNum(char num[]){
    strcpy(acctNum,num);
}

double Cust::getCurrBalance(){
    return currBalance;
}

void Cust::setCurrBalance(double balance){
    currBalance = balance;
}

void Cust::addToCurrBalance(double amount){
    currBalance += amount;
}

void Cust::subFromCurrBalance(double amount){
    currBalance -= amount;
}

void Cust::setAcctFN(char firstName[]){
    strcpy(acctFN,firstName);
}

void Cust::setAcctLN(char lastName[]){
    strcpy(acctLN,lastName);

}

char * Cust::getAcctFN(){
    return acctFN;
}

char * Cust::getAcctLN(){
    return acctLN;
}

void Cust::setPIN(int pin){
    Cust::pin = pin;
}

int Cust::getPIN(){
    return pin;
}

Here is my stack trace:

 Index  Function
--------------------------------------------------------------------------------
 1      msvcr90d.dll!68d7f693() 
 2      [Frames below may be incorrect and/or missing, no symbols loaded for msvcr90d.dll]
*3      P3.exe!main(int argc=0, char * const * argv=0x0036fcd0) 
 4      P3.exe!_FreeLibrary@4() 
 5      P3.exe!@ILT+170(__except_handler4)() 
 6      kernel32.dll!75eb3677() 
 7      ntdll.dll!77b29d72() 
 8      ntdll.dll!77b29d45() 
  • 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-13T06:17:08+00:00Added an answer on May 13, 2026 at 6:17 am

    A few things to check (sorry not going to download the code):

    1. does g++ *.c have warnings? If so fix them.
    2. does g++ -W have warnings? If so fix them.
    3. does g++ -W -Wall have warnings? If so fix them.
    4. does g++ -W -Wall -Wextra have warnings? If so fix them.
    5. does g++ -W -Wall -Wextra -ansi have warnings? If so fix them.
    6. does g++ -W -Wall -Wextra -ansi -pedantic have warnings? If so fix them.

    On microsoft try adding /W4 to the command line to turn the warning up, again fix any issues.

    Odds are you are doing something “silly” and chances are that the compiler can help you catch what it is.

    Edit:

    From compiling your code with the flags above you will see:

    Cust.h:33: error: ISO C++ forbids zero-size array ‘acctNum’
    Cust.h:34: error: ISO C++ forbids zero-size array ‘acctFN’
    Cust.h:35: error: ISO C++ forbids zero-size array ‘acctLN’
    Cust.h:38: error: ISO C++ forbids zero-size array ‘fileName’
    Cust.h:33: error: ISO C++ forbids zero-size array ‘acctNum’
    Cust.h:34: error: ISO C++ forbids zero-size array ‘acctFN’
    Cust.h:35: error: ISO C++ forbids zero-size array ‘acctLN’
    Cust.h:38: error: ISO C++ forbids zero-size array ‘fileName’

    So your code is not valid C++. You are copying a name into an array that is too small – the array has 0 elements. What you really need to do is give the arrays a size when you declare them or declare them as pointers and then use “new” to allocate the right amount of memroy.

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

Sidebar

Ask A Question

Stats

  • Questions 385k
  • Answers 385k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In my experience web services will return the exceptions serialized… May 14, 2026 at 11:30 pm
  • Editorial Team
    Editorial Team added an answer I do automated testing stuff in Python. I tend to… May 14, 2026 at 11:30 pm
  • Editorial Team
    Editorial Team added an answer You need to use this format to connect to a… May 14, 2026 at 11:30 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.