3

I have created a auto typer bot in C which simulate keys.

It first search for a paragraph according to user input and then simulate each character of that paragraph.

I have 3000 paragraph database and total number of character is more than 1,000,000.

So, please tell me, can i store all data in one character array?

My code is ---

char database[] = {"A string with more than 1,000,000 characters"};
char *start_position;
gets(s); // a small string given by user, this input is used to search which paragraph user want to simulate.
start_postion=strstr(database, s);
function_for_key_simulation();......

I have readed here that big array cause buffer overload. Please suggest me alternative methods to perform this task.

Community
  • 1
  • 1
Prabhakar Rai
  • 105
  • 11
  • 1
    It depends is the right answer. Depends on how you declared/allocated the array. But in any case, a 15 (or 16) byte char array is unlikely to be hitting any limits. Are you experiencing any specific problem with actual code or are you just asking theoretically? – kaylum Apr 29 '16 at 04:29

1 Answers1

4

For string literals like char *s = "abcd"; the standard requires the compiler should support a limit of at least 4095 chars, as defined in cstd 5.2.4.1:

The implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits:

-- 4095 characters in a string literal (after concatenation)

That means you can safely define a string literal of 4095 chars. Make more chars beyond that will make the code not portable. Since some compiler may support more and some not.

For char arrays, like char array[N]; it depends on the implementation and platform, it's normally not recommended to make huge arrays, if you need a big buffer to hold data, use dynamic allocated memory instead, which will give you exact feedback(return NULL) when it fails, other than a running time buffer overflow of other unexpected behavior.

Community
  • 1
  • 1
fluter
  • 13,238
  • 8
  • 62
  • 100