I want to generate two random chars (Or a string of two random chars), concatenate them into a string and store it in a 2D array.
Does anyone have any idea why this is not working? (I know the code isn't particularly good but I guess you have to start somewhere). Thanks.
int TimeTracking(void) { // Function with the purpose of counting how many
// times it has been invoked and return it
static unsigned int call_count = -1;
call_count++;
return call_count;
}
int PrinterFunction (void) {
int LocalCallCount = TimeTracking();
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int randomvar = 0;
fileObject = fopen("Default.txt", "a");
char MasterArray[1440][10];
char AircraftRandomLetter1[10]; // Store random letter
char AircraftRandomLetter2[10]; // Store second random letter
randomvar = rand() % 26; // Gen random num for gen random letter
AircraftRandomLetter1[LocalCallCount] = alphabet[randomvar]; // Access
// Violation here???
randomvar = rand() % 26; // Gen random num for gen random letter
AircraftRandomLetter2[LocalCallCount] = alphabet[randomvar];
strcat(AircraftRandomLetter1[LocalCallCount],
AircraftRandomLetter2[LocalCallCount]);
MasterArray[LocalCallCount] = AircraftRandomLetter1[LocalCallCount];
fputs(AircraftRegisterRequestingTakeOffIdentifer[LocalCallCount],
fileObject);
// Print result to file
fputs("\n", fileObject);
fclose(fileObject);
return 0;
}
In reply to chux, is this somewhat in the right direction? :
randomvar = rand() % 26;
strncpy(AircraftRandomLetter1[LocalCallCount], alphabet, randomvar);
AircraftRandomLetter1[LocalCallCount + 1] = '\0';
randomvar = rand() % 26;
strncpy(AircraftRandomLetter2[LocalCallCount], alphabet, randomvar);
AircraftRandomLetter1[LocalCallCount + 1] = '\0';
strncat(AircraftRandomLetter2[LocalCallCount],
AircraftRandomLetter1[LocalCallCount], sizeof(AircraftRandomLetter1));
fputs(AircraftRegisterRequestingTakeOffIdentifer[LocalCallCount],
fileObject);
// Print result to file