Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
void append(char* start, char temp)
{
int len = strlen(start);
start[len] = temp;
start[len+1] = '\0';
}
int main()
{
int emptyIterator = 0;
int arrayIterator = 0;
int numberSize = 10;
int fileSize;
int x = 100;
int numbers[x];
// memset(numbers, 0, sizeof(int), 100);
int inner;
int outer;
int worstArraysize;
char arrayMalloc;
char *buffer;
int *array;
int bufferSize;
// memset(array, 0, sizeof(array));
FILE *filePointer;
for (emptyIterator = 0; emptyIterator < 100; emptyIterator++)
{
numbers[emptyIterator] = 0;
}
filePointer = fopen("C:\\users\\hello\\desktop\\test.txt", "rt");
fseek(filePointer, 0, SEEK_END);
fileSize = ftell(filePointer);
rewind(filePointer);
bufferSize = sizeof(char) * (fileSize + 1);
buffer = malloc(bufferSize);
memset(buffer, '\0', bufferSize);
printf("\n%d filesize\n", fileSize);
printf("\n%d buffersize\n", bufferSize);
fread(buffer, 1, fileSize, filePointer);
fclose(filePointer);
worstArraysize = sizeof(char) * ((fileSize / 2) + 1 );
array = malloc(worstArraysize);
memset(array, '\0', worstArraysize);
for(emptyIterator = 0; emptyIterator <= worstArraysize; emptyIterator++)
{
void * temp;
temp = malloc(sizeof(char) * (numberSize));
array[emptyIterator] = (int)temp;
memset((char *) array[emptyIterator], '\0', numberSize);
((char *)array[emptyIterator])[0] = 's';
printf("\ntemp is : %x array location %x string num%d ram location %x: %d\n", temp, &array[emptyIterator], emptyIterator, array[emptyIterator], (((char*)array[emptyIterator])[0]));
}
printf("Time to double check out work\n\n");
for(emptyIterator = 0; emptyIterator <= worstArraysize; emptyIterator++)
{
printf("poisition %d , array ram : %x , string location %x, first char %c\n", emptyIterator, &array[emptyIterator], array[emptyIterator], *((char *)array[emptyIterator]));
}
return 0;
system("Pause");
}
Needless to say the code has gotten pretty crazy.
Here is output
Code:
poisition 0 , array ram : 660f88 , string location 660fa0, first char 0poisition 1 , array ram : 660f8c , string location 660fb8, first char Ąpoisition 2 , array ram : 660f90 , string location 660fd0, first char spoisition 3 , array ram : 660f94 , string location 660fe8, first char spoisition 4 , array ram : 660f98 , string location 661000, first char spoisition 5 , array ram : 660f9c , string location 661018, first char spoisition 6 , array ram : 660fa0 , string location 661030, first char spoisition 7 , array ram : 660fa4 , string location 661048, first char spoisition 8 , array ram : 660fa8 , string location 661060, first char spoisition 9 , array ram : 660fac , string location 661078, first char spoisition 10 , array ram : 660fb0 , string location 661090, first char spoisition 11 , array ram : 660fb4 , string location 6610a8, first char spoisition 12 , array ram : 660fb8 , string location 6610c0, first char spoisition 13 , array ram : 660fbc , string location 6610d8, first char spoisition 14 , array ram : 660fc0 , string location 6610f0, first char spoisition 15 , array ram : 660fc4 , string location 661108, first char spoisition 16 , array ram : 660fc8 , string location 661120, first char s
This is still a major work in progress, I know a LOT has to be done to it still. But what I am mostly concerned with now is why the two loops are overlapping. I like all the different pointers and see this technique as being useful (don't want to hear how it isn't, i'm going through this with someone else)...I just want to know what the problem is here for why they are overlapping ram locations.