Help with my application's user defined configuration

I am currently writing code for my application's user defined configuration.

The "WriteConfiguration()" function takes two arguments; The setting to be changed, and the new value for the setting. During the execution of this function, the file is opened and loaded into a buffer. The buffer is then passed to another function where each setting is separated into a new row in the Data[][] array. Further separation of the array separates each individual setting from it's value. Once the setting from the "WriteConfiguration()" argument is found, the corresponding value is replaced with the new one. All of the loaded settings in the Data[][] array are then placed in a new buffer and written to the configuration file.

Upon execution of the "WriteConfiguration()" function, I recieve the error:

Unhandled exception at 0x77b615de in WebClient2.exe: 0x00000000: The operation completed successfully.

I have also noticed that in the "WriteConfiguration()" function,

Settings.Separation(SettingsFile.Data[c], *"=", false);

when "c = 0;" "cout << Settings.Data[0];" displays nothing.


Here is the source code:
WriteConfiguration();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
int WriteConfiguration(char Setting[256], char NewValue[256])
{
	File SettingsFile;
	File Settings;
	char WriteBuffer[1024] = "\0";
	int EntryNumber = 0;
	int Start = 0;
	char FullPath[256] = "\0";
	char FileBuffer[1024*5] = "\0";
	
	GenerateFullPath("C:\\Users\\Admin\\Desktop\\WebScanner\\Config\\", "Config", ".cfg", FullPath);
	
	if (SettingsFile.Read(FullPath, *"?", FileBuffer) == 0)
{
	cout << "Configurations Loaded Successfully" << endl;

}
	
int a = 0;


	for (int c = 0;  SettingsFile.StringCount != c; c++)
{
	Settings.Separation(SettingsFile.Data[c], *"=", false);
	

		if (strcmp(Settings.Data[0], Setting) == 0)
	{
		
			if (EntryNumber == 1)
		{
			WriteBuffer[a] = *"?";
			a++;
		}

			if (Start == 0) Start = 1;
			for (int b = 0; Settings.Data[0][b] != NULL; b++, a++) WriteBuffer[a] = Settings.Data[0][b];	
			WriteBuffer[a] = *"=";
			a++;
			for (int b = 0; NewValue[b] != NULL; b++,a++)WriteBuffer[a] = NewValue[b];
	
		}

			else
		{
			cin.get();
				if (Start == 0)
			{
				EntryNumber = 1;
				Start = 1;
			}
				else
			{
				WriteBuffer[a] = *"?";
				a++;
			}

			for (int b = 0; Settings.Data[0][b] != NULL; b++, a++) WriteBuffer[a] = Settings.Data[0][b];
			WriteBuffer[a] = *"=";
			a++;
			for (int b = 0; Settings.Data[1][b] != NULL; b++, a++) WriteBuffer[a] = Settings.Data[1][b];

		
		}
	
		}

	if (SettingsFile.Write(FullPath, WriteBuffer, true, NULL) == 0) return 0; //Write Altered Settings

		else return 1;
}


String Arrangement and File Loading
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class StringArrangement
{

public:
char Data[25][1024];
int StringCount;

int Separation(char NewBuffer[1024*3], char SeparationCharacter, bool KeepCharacter)
{
	int b = 0;
	int a = 0;
	int c = 0;
	int d = 0;
	StringCount = 0;

////Temporary fix for clearing data buffer//
	for (int b = 0; a <= 25; a++, b = 0)
{
		for (;b <= 32; b++) Data[a][b] = 0;

}
	a = 0;
////Temporary fix for clearing data buffer^^//

	
	

	while (NewBuffer[a] != NULL)
{
	
		for (int b = d; (NewBuffer[a] != SeparationCharacter)&&(NewBuffer[a] != NULL); b++, a++) Data[c][b] = NewBuffer[a];
	
		c++;

		if (KeepCharacter == true)
		{
			Data[c][b] = SeparationCharacter; // Temporary fix for keeping important characters
			d = 1;
		}
		b++;
		a++;
		StringCount++;
}
	
	
	return 0;
}


};


class File: public StringArrangement
{

public:
#define MaxFileBuffer 1024*5

int Read(char directory[256], char SeparationCharacter, char FileBuffer[MaxFileBuffer])
{
	
	ifstream File;
	File.open(directory);
	
	if (File.is_open() == 1) 
{
	File.read(FileBuffer, MaxFileBuffer);
	File.close();

		if (SeparationCharacter != NULL)
	{
			if (Separation(FileBuffer, SeparationCharacter, 0) == 0) return 0;
	}

		else return 0;
			
}

	else return 1;
		
}


int Write(char directory[512], char Data[BufferLength], bool OverWrite, char FileSeparationCharacter[32])
{

	int b = 0;
	ofstream File;
	char FileBuffer[MaxFileBuffer] = "\0";
	

		if (OverWrite == false)
	{
		
		Read(directory, NULL, FileBuffer);
		while (FileBuffer[b] != NULL) b++;
		for (int a = 0; FileSeparationCharacter[a] != NULL; a++, b++) FileBuffer[b] = FileSeparationCharacter[a];
		for (int a = 0; Data[a] != NULL; a++, b++) FileBuffer[b] = Data[a];
		File.open(directory);
		File << FileBuffer;
		File.close();

	}
		else 
	{
		
		for (int a = 0; Data[a] != NULL; a++, b++) FileBuffer[b] = Data[a];
		File.open(directory);
		File << FileBuffer;
		File.close();
	}

	return 0;
}

private:


};
Last edited on
Can I ask what the asterix in *"=" is for ? I've never seen it before nor can I find documentation on it...

I'm taking a wild guess here:
Change this:
Settings.Separation(SettingsFile.Data[c], *"=", false);
To:
1
2
char myChar = *"=";
Settings.Separation(SettingsFile.Data[c], myChar , false);
Can I ask what the asterix in *"=" is for ?


It's both beautiful and horrific.

"=" is a string literal; it gives a pointer to the first element in a (const) array of char (which in this case contains only a single char).

How do we get what a pointer is pointing at? With the * operator. So *"=" is the char =.

The more traditional way to have the char = would be '='.

Here's some example code showing this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

using namespace std;

int main()
{
  char array[2];
  
  array[1] = 0;
  array[0] = 'b'; // The more traditional way
  
  cout << array << endl;
  
  char x = *"r"; // Both hideous and beautiful. Ah, C.
  array[0] = x;
  cout << array; 
}

Last edited on
Thanks Moschops, indeed it is both hideous and beautiful ~~~
both hideous and beautiful ~~~


Reminds me of my ex. :p
*"="

Why on earth would you ever do this? Other than to be obscure
Old C habit? Which reminds me, what is with the brackets and indentation usage? What style/language is that from, I've never seen it written like that before.
Why on earth would you ever do this?


Because you're so phreaking leet! Yeah!
Last edited on
Old C habit? Which reminds me, what is with the brackets and indentation usage? What style/language is that from, I've never seen it written like that before.



It is just my own personal style for organizing code. I am self taught and have not received any formal teachings.
It's both beautiful and horrific.


Gotta love C. :3
It is just my own personal style for organizing code. I am self taught and have not received any formal teachings.


I was wondering since I personally found it hard to read. Over the years I've switched styles, mainly start with Stroustrup's style, then moved to the JAVA style. It's more important that you can understand than others, but it does help when others can read it just as easily.

As for displaying an empty line, have you verified that the file doesn't contain a blank starting line? Or maybe a line that isn't read properly; ie it has a special character in it that the program doesn't recognize?

That's my only thought, and I looked through the code but nothing really pops out at me. Best of luck.
After switching to "Release" mode in Visual Studio 2010, the problem seized to occur and the operation completed successfully. This is quite strange. Should I worry about this? Is the compiler at fault or is there possibly something wrong with my code that is only discovered in debug mode?
I do know there is a difference between the release bins and the debug bins, but I've personally never encountered an issue with it. Maybe it's an IDE issue?
Topic archived. No new replies allowed.