- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
因此,我读取了某个文件作为输入并将其加载到内存中,并获得了一个 cstring char* 文本。
我想将该字符串拆分为一定数量的字符串。例如,假设我有 4 个线程,我希望每个线程打印字符串的某个“片段”(不一定按顺序)。
int num_threads = 4;
char *filename = "file.txt";
int file_size = load_file_to_mem(filename, &text); // I made this and it works.
int text_size = strlen(text);
int substring_size; // that would be the size of each substring
char to_thread[num_threads][block_size];
如何将 *text 字符串拆分为 4 个相同大小的子字符串,也就是说,如何找到 block 大小以便让每个线程接收该大小的子字符串?
最佳答案
除非我误解了这个问题,否则一种方法是使用 ceil()函数:num_threads - 1
每个子字符串的长度都是 ceil(test_size/num_threads) + 1
。剩余的单个子字符串的长度为 test_size - (num_threads - 1) * ceil(test_size/num_threads) + 1
。
您可能会这样做,因为 num_threads
可能不会将 test_size
平均分配。添加一个字节以包含每个子字符串的空终止符的空间。
关于c - 将一个字符串分成一定数量的子串(C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32596494/
我正在尝试创建一个程序,其中字符串的前三个字符重复给定次数,如下所示: foo('Chocolate', 3) # => 'ChoChoCho' foo('Abc', 3) # => 'AbcAbcA
我有以下字符串: std::string str = "Mode:AAA:val:101:id:A1"; 我想分离一个位于 "val:" 和 ":id" 之间的子字符串,这是我的方法: std::st
DNA 字符串可以是任意长度,包含 5 个字母(A、T、G、C、N)的任意组合。 压缩包含 5 个字母(A、T、G、C、N)的 DNA 字母串的有效方法是什么?不是考虑每个字母表 3 位,我们可以使用
是否有一种使用 levenstein 距离将一个特定字符串与第二个较长字符串中的任何区域进行匹配的好方法? 例子: str1='aaaaa' str2='bbbbbbaabaabbbb' if str
使用 OAuth 并使用以下函数使用我们称为“foo”(实际上是 OAuth token )的字符串加密 key public function encrypt( $text ) { // a
我是一名优秀的程序员,十分优秀!