When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
37 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
It says you can concatenate them like this.
const char* str = “string part 1” “string part 2”
but you cant say “the entire string here”.
when the program compiles, “string part 1” “string part 2” will turn into “string part 1string part 2”
i’m not sure about all that sorry.
@devout breach Has your question been resolved? If so, type !solved :)
what compiler do you use?
have you tried using the heap to store that much data?
so MSVC alright
what about the other part of my message?
you'd likely need to copy it in chunks. if MSVC complains about the length of the string - copying it all i one go will just move the problem into the copying part
where do you get your string from btw?
that doesn't answer my question
you, again, don't answer the question.
it matters, because the way you get the string may impact on the wat you can store it
is it compile-time dynamic, or run-time dynamic? is it a file or a stream or a socket? all of these things matter, because they affect what tools you can and should use
e.g. if said string is stored in a file - one can read the file in chucks, populating their buffer as they go. same goes to IPC mechanisms
that sentence makes no sense. sorry
so it is in a file, you just can't use copy-paste, or it's on the other side of a socket?
you sure?
how about the file said string is hardcoded in? 
so you're basically writing your own #embed because MSVC doesn't have it?
or #include, whatever
i don't know what 'compile it from there' means in is context.
what i suggest is that you store it in a file, have your program open the file and read it in chunks (it'll be up to you whther to combine said chunks into a one big buffer or not)
i don't believe that will work. #include is merely a copy paste. the compiler will truncate it still
yeah, #embed would be ideal, for a bunch of reasons
ship the file with the exe
this reply makes me think you didn't read the link, i'm going to be honest, chief
no. it won't.
#pragma warning(disable : error_code_goes_here)
its inherent to MSVC, "disabling the error" would require you to edit the MSVC source code
What if you simply use the heap?
My bad!
all good 🙂
there are compilers that allow you to use #embed, which is what you want, yes
🤷♂️
you're more than welcome to try clang if you want. though 200,000 chars string is quite large...
if you want to stick to MSVC, though, just open your main.c file (or whatever file you want to put the string into before compiling that file) with another .c file, essentially```c
FILE* cfile = fopen("main.c", "a");
FILE* txtfile = fopen("input.txt", "r");
fprintf(fp, "char arr[] = {");
for (int i = 0; i < 200000 / 10000; i++) {
char arr[10001];
fgets(arr, sizeof(arr), txtfile);
fprintf(cfile, ""%s"", arr);
}
fprintf(cfile, "}");
fclose(txtfile);
fclose(cfile);
good luck reopening that in VS or VSCode later to check, though -- your file will be somewhat large, and MS code editors tend to choke on large files
that is doing it with pure strings, just programmatically. that is taking the literal text from input.txt and inserting it into main.c in a way that won't make the compiler truncate the strings, see #1311333635382841444 message
i suggest you put it in a header file, now that i think about it, though. you dont want to reopen that file if you dont have to (MS text editors chokes on large files, generally)
if you run that code, the pure, literal string will be purely, literally in main.c -- or a header file, which you #include into main, same thing