Questions tagged [strcat]

A standard C function that appends a copy of the source string to the destination string.

The declaration of strcat function which is found in string.h is:

char *strcat(char *dest, const char *src)

This function appends the string pointed to by src to the end of the string pointed to by dest. Here,dest is a pointer to the destination array, which should contain a C string, and be large enough to contain the concatenated resulting string and src is the string to be appended. This should not overlap destination.

strcat returns a pointer to the resulting string dest.

For more information, check the man page.

529 questions
-1
votes
3 answers

Adding space to char** element with strcat

I got array like this: char *family[3] ={"son", "father", "sister"}; and I want to align length of each element to the same size by using function strcat(son," "); but I get core dumped instead.
-1
votes
5 answers

Reverse words in C Language

I'm trying to reverse the letters for words in a sentence. I am also trying to store these words in a new char array. At the moment I getting a runtime error, which for all my tweaking I can not solve. My approach is to create a new char array the…
Calgar99
  • 1,670
  • 5
  • 26
  • 42
-1
votes
1 answer

append const char variables wih string

I have 2 integers, whom I converted to const char* by passing to a user defined function. Now I want to append these 2 variables into a command line string as "gnome-terminal -x sh -c 'cd; cd project/into_bot/; sh ./matlab_batcher.sh localize…
Lakshmi Narayanan
  • 5,220
  • 13
  • 50
  • 92
-2
votes
2 answers

cannot append string in C (program stops)

I'm trying to append a string, but whenever it gets to the strcat() function the program exits without printing the string. I've been running this code from within Visual Studio as well as from its own .exe file and get the same result. Can anybody…
-2
votes
2 answers

Why the strcat function move the pointer to the next character?

So, my problem is pretty simple, I don't know why the first segment of code does not work properly. The program read a string of 12 characters from a pipe and the strcat fuction moves the pointer of buff from the first character to the next every…
-2
votes
2 answers

How to join characters?

#include #include int main(void) { char rez[100] = "\0"; char t = 97; char temp; strcpy(temp, t); strcat(rez, temp); printf("%s", rez); return 0; } I want to join the character 'a' to the result…
Fei Xu
  • 1
  • 1
-2
votes
2 answers

Iterate C char array of size 100000 takes huge time

Just try to iterate a character array of size 100000 but it takes 8-9 sec. But for int its takes some milli second. int i; char str[100005]; str[0] = '\0'; for(i=1;i<10000;i++){ strcat(str, "HelloWorld"); } …
Eklavya
  • 17,618
  • 4
  • 28
  • 57
-2
votes
2 answers

how do i combine two character arrays without this error?

Im learning how to combine two arrays and made this simple code to understand it. I keep getting the error "array must be initialized with a brace-enclosed initializer" what does this mean and how can I fix it? thx char a[20] ="hello"; char b[20] =…
pat101
  • 1
-2
votes
1 answer

strcat + strlen has strange behavior

guys i want to find the cause why this strcat (or strlen) has this issue: when i write: int main(int argc, char* argv[]) { if(argv[1] != '\0') { const char* navegador = "C:\\Program Files\\Mozilla Firefox\\firefox.exe "; …
-2
votes
2 answers

character missing on using Realloc and strcat on multidimensional array?

helloeveryone. I am fairly new to programming and currently trying to learn C programming to advance further in any of my projects. I've just learned how to use malloc and realloc, and all seemed good until I attempted to use strcat to combine two…
Jay Choi
  • 1
  • 1
-2
votes
1 answer

Replacements for deprecated strcpy/strcat when using char*

I have code for a 'zombie translator' as an example from my professor. From what I can tell it takes a string of english words and applies a few rules to it via functions. It currently uses strcpy and strcat to do this, however it will not compile…
lana
  • 33
  • 6
-2
votes
1 answer

String / char * concatinate, C

Am trying to open a file(Myfile.txt) and concatenate each line to a single buffer, but am getting unexpected output. The problem is,my buffer is not getting updated with the last concatenated lines. Any thing missing in my code? Myfile.txt (The…
kahsay.k
  • 61
  • 7
-2
votes
1 answer

Safe way to concat two strings in C

I have the following code that concats two strings: char *getConcatString(char *str1, char *str2) { char *finalString = malloc(1 + strlen(str1) + strlen(str2)); // Needs to be freed by the user after use if(finalString == NULL) …
user3266083
  • 103
  • 3
  • 12
-2
votes
1 answer

C initials program returned "Segmentation fault"

I am working on a initials project where you enter a name and it prints the initials. When I try and combine the strings it returns Segmentation fault instead of the initials. #include #include #include #include…
Marcus Mardis
  • 83
  • 1
  • 1
  • 8
-2
votes
1 answer

strcpy and strcat return an error in c

char first[]="aa"; strcat(first,ar[0]); char *second[10]; strcpy(second[0],first); I want to use strcat and strcpy. strcat works but there is an error in strcpy. how can I modified it?
esrtr
  • 99
  • 2
  • 12