Linked Questions
11 questions linked to/from Concatenating strings in C, which method is more efficient?
17 votes
3 answers
13k views
How can I optimize these loops (with compiler optimization disabled)?
I need to optimize some for loops for speed (for a school assignment) without using compiler optimization flags. Given a specific Linux server (owned by the school), a satisfactory improvement is to ...
51 votes
2 answers
6k views
Is it safe to read past the end of a buffer within the same page on x86 and x64?
Many methods found in high-performance algorithms could be (and are) simplified if they were allowed to read a small amount past the end of input buffers. Here, "small amount" generally ...
3 votes
5 answers
69k views
concatenating strings in a printf statement
I am compiling with: gcc 4.7.2 c89 I have the macro: #define LOG_ERR(fmt, ...) \ fprintf(stderr, "[ERROR] %s:%d: error [%s] " fmt "\n&...
2 votes
5 answers
8k views
How do I concatenate two C-style (null-terminated) strings?
I want to concatenate two strings which are defined like this: char hello[] = { 'H', 'e', 'l', 'l', 'o', '\0' }; char world[] = { ',', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\0' }; I understand that I ...
0 votes
9 answers
9k views
Concatenating two const char * in C
I am working with the const char * type in C. Due to the libraries I am using I am trying not to use or include other libraries (namely cstring). The function I am working in is passed a buffer of ...
0 votes
5 answers
837 views
how many null bytes, concatenating strings in C
If i want to concatenate 2 strings in C, do i have to allocate an extra null char for every string or one is enough? int main(){ char *s1 = NULL; char *s2 = NULL; char *s1_s2 = NULL; ...
1 vote
2 answers
2k views
C Program to Expand and Run PHP
How would I make a GCC C program on Linux that: has a PHP program script inside itself, not as a separate file expands itself out to /tmp shells out to php CLI command line to run the PHP script ...
0 votes
2 answers
874 views
c string construction
I'm trying to parse argv back into a single string to use for a system call. The string shows up fine through the printf call (even without the \0 terminator), but using it as a parameter to system ...
0 votes
1 answer
1k views
malloc and snprintf bus core dump
Function which worked previously, suddenly refuses cooperation. More precisely this snippet: //If not, add to UIDS printf("line 78\n"); free(s2); printf("line 82\n"); char * ss = ...
1 vote
2 answers
196 views
Seg Fault when reading from file, and using pthread_create
Whenever I run my code I get through 4 iterations of reading the file and creating a pthread until it segfaults with ID 11. The segfault is caused by my print ln: printf("%s %s\n", "Calling ...
1 vote
3 answers
198 views
how to run a bit of PHP code from C [duplicate]
I have the bellow bit of code that works just fine. FILE *pipe_fp; if((pipe_fp = popen("php", "w")) == NULL) { perror("popen(PHP)"); exit(1); } fputs("<?php echo process('xx'); ?&...