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
5
votes
4 answers

C char to string (passing char to strcat())

my problem is in convert a char to string i have to pass to strcat() a char to append to a string, how can i do? thanks! #include #include char *asd(char* in, char *out){ while(*in){ strcat(out, *in); // <-- err arg…
frx08
  • 4,222
  • 8
  • 37
  • 45
4
votes
5 answers

Matlab character to string convertion problem. What function to use?

x = 1234 56789 7654 x(1) is 1, x(2) is 2 and so on... there are 5 spaces in between.. size(x) = 1 23 One row with 23 columns I've tried using num2str, strcat but I cannot club the numbers. y = num2str(x), y = strcat(x) I want it to be..…
emil
  • 105
  • 3
  • 8
4
votes
3 answers

strcat() vs sprintf() inside a loop

I have a program that's removes every variables inside a string. Theses variables start with '$'. So, for, example, if I give a string like [1,2,$1,$2], it should return just [1,2]. However, which loop is better for perfomance? This: while (token !=…
Sinayra
  • 175
  • 1
  • 13
4
votes
5 answers

What is another alternative to strcat and strncat functions in C?

This is the specific section of code where I am facing issues using both strcat() and strncat() functions to concatenate two strings. The strcat() function is declared as char *strcat(char *dest, const char *src) and strncat() as char *strncat(char…
Nishit Mengar
  • 139
  • 1
  • 2
  • 10
4
votes
5 answers

Why C11 standard doesn't drop unsafe strcat(),strcpy() functions?

C11 & C++14 standards have dropped gets() function that is inherently insecure & leads to security problems because it doesn't performs bounds checking results in buffer overflow. Then why C11 standard doesn't drop strcat() & strcpy() functions?…
Destructor
  • 14,123
  • 11
  • 61
  • 126
4
votes
7 answers

strcat paste second string at beginning of first string

i use strcat() to connect two strings like: #include #include int main(int argc, char *args[]) { char *str1; // "456" char *str2; // "123" strcat(str1,str2); printf("%s",str1); …
Refael
  • 6,753
  • 9
  • 35
  • 54
4
votes
2 answers

Octave strcat ignores added spaces

Octave adds spaces with strcat In Octave I run these commands: strcat ("hel", " ", "lo") I get this result: ans = hello Instead of what I expected: ans = hel lo strcat to me sounds like "concatenate strings". A space is a valid character, so…
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
4
votes
4 answers

How to copy or concatenate two char*

How do you concatenate or copy char* together? char* totalLine; const char* line1 = "hello"; const char* line2 = "world"; strcpy(totalLine,line1); strcat(totalLine,line2); This code produces an error! segmentation fault I would guess that i…
mister
  • 3,303
  • 10
  • 31
  • 48
3
votes
1 answer

strcat overflow?

Could someone explain why is my strcat doing this? I can't seem to find out why I am rewriting on a part of the source string. The output is like this: New String: HelloThis shall be after my backslash 0 in str1h 0 in str1 global strcat …
Abdellah IDRISSI
  • 530
  • 1
  • 5
  • 16
3
votes
1 answer

strcat expects a restrict * char?

I am trying to concat two const char * strings. When i have a statement like strcat(a,b) I get the warning expected ‘char * restrict’ but argument is of type ‘const char *’ is there a way to call strcat that will not produce the warning? Thanks!
user974703
  • 1,653
  • 4
  • 20
  • 27
3
votes
6 answers

Ways to build string in c

I'm building a string here based on 4 arguments and calling it with system(), but seems kinda messy the way i have done it. Is there a more correct way i should have done this and not use all those strcat and str1-4? #include #include…
Darkmage
  • 1,583
  • 9
  • 24
  • 42
3
votes
5 answers

How does strcat() fucntion actually works and its alternate

Let's take an example. #include #include int main() { char str1[7] = "hello "; printf("Initial size of str1 is: %d\n", strlen(str1)); char str2[] = "buddy"; printf("%s\n", strcat(str1, str2)); printf("Final…
Raon
  • 113
  • 8
3
votes
2 answers

strcat eccentric behavior

I wrote this simple C program and couldn't quite figure out this bizarre behavior of strcat long sum(long col, char* path, char* path2){ printf("%s\n",path2); strcat(path,".endlines"); printf("%s\n",path2); return 0; } int…
NQC
  • 33
  • 5
3
votes
3 answers

C error expected ‘char **’ but argument is of type ‘char (*)[10]’

I am trying to implement my version of strcat. However, I get below warning and my code crashes while running. I am passing &p from main to make permanent changes to variable p in the main function. Warning: note: expected ‘char **’ but argument is…
Ravi
  • 173
  • 1
  • 10
3
votes
2 answers

Scanf erases a char array unwillingly

See the following program: #include #include #include #include main(void){ printf("Array concatenateor\n-------------------------\n"); //declarations char s1[50],s2[50],s3[50]; short int n=0; …
andreihondrari
  • 5,743
  • 5
  • 30
  • 59
1
2
3
35 36