I feel semi-retarded posting this, but I have no idea why my program is blowing up when it reads a string literal from the keyboard (i.e. then assigning it to a pointer).
Been debugging for over an hour and the program keeps blowing up when it reads from the keyboard.
I have tried everything to fix this. Initializing the string to a string literal (i.e. the compiler said it had a problem with nullptr). It is almost like I have an invisible character somewhere. If anyone can tell me what I'm doing wrong, I would greatly appreciate it.
main.cpp
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include <iostream>
#include <fstream>
#include "protocol.h"
int main()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
int menuChoice = 0;
char * fileName = nullptr;
char * byteArray = nullptr;
char * hexArray = nullptr;
int numberOfBytes = 0;
PrintMenu();
GetMenuChoice(menuChoice);
ExecuteMenuChoice(menuChoice, fileName, byteArray, hexArray, numberOfBytes);
return 0;
}
protocol.cpp
void GetFile(char * fileName)
{
//Prompt user for binary file
std::cout << "\nEnter filename: " << std::endl;
//Read in location of binary file
std::cin.ignore(std::cin.rdbuf()->in_avail());
std::cin.getline(fileName, 256);
std::cin.clear();
std::cin.ignore(std::cin.rdbuf()->in_avail());
}
protocol.h
#ifndef PROTOCOL_H
#define PROTOCOL_H
//Function declarations
void PrintMenu();
void GetMenuChoice(int &menuChoice);
void ExecuteMenuChoice(int menuChoice, char *& fileName, char *& byteArray,
char *& hexArray, int numberOfBytes);
void NewLine();
void ThankUser();
void ErrorMessage();
#endif