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
3
votes
2 answers

Convert int to string and concatenate it in another string (C language)

I am trying to write a code in C language to store the following series of numbers in a string "0.123456789101112131415...". I am tried this code: char num[2000], snum[20];; num[0] = '0'; num[1] = '.'; for(int i = 1; i <…
3
votes
3 answers

strcat adds junk to the string

I'm trying to reverse a sentence, without changing the order of words, For example: "Hello World" => "olleH dlroW" Here is my code: #include #include char * reverseWords(const char *text); char * reverseWord(char *word); int…
DarkSuniuM
  • 2,523
  • 2
  • 26
  • 43
3
votes
3 answers

C strcat garbage characters

I have a function in C where i am trying to get strings from two different locations (unknown size, could be quiet large) and combine them into one string and return them. If i just print the two strings then I get the correct result, but when I try…
vimalloc
  • 3,869
  • 4
  • 32
  • 45
3
votes
2 answers

Deep understanding of strcat and strlen functions

We know that strcat() recevies a poiner to a destination array as parameters and concatenate them with source string. The destination array should be large enough to store the concatenated result. Recently i found out that it is still possible for…
casper
  • 259
  • 4
  • 18
3
votes
2 answers

string literals and strcat

I am not sure why strcat works in this case for me: char* foo="foo"; printf(strcat(foo,"bar")); It successfully prints "foobar" for me. However, as per an earlier topic discussed on stackoverflow here: I just can't figure out strcat It says, that…
Neon Flash
  • 3,113
  • 12
  • 58
  • 96
3
votes
3 answers

Concatenating strings without buffers

Is there a way to concatenate strings without pre-allocating a buffer? Consider the following: int main() { char buf1[] = "world!"; char buf2[100] = "hello "; char * p = "hello "; // printf("%s", strcat(p, buf1)); // UB …
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
3
votes
1 answer

imwrite giving inconsistent error in Matlab

I wrote a code to clean and print multiple images, data_1=csvread(data) for h=1:30 im_old=imread(strcat('catches\image_generator (',int2str(h),').png')); im_bw=func_bw(im_old); im_2=func_clean_tr(im_bw); …
Pranav Totala
  • 148
  • 2
  • 14
3
votes
5 answers

Why isn't the 'strcat' function working?

I am trying to concatenate arrays from a structure using strcat. My code looks as follows: int main(){ //Implementation of Search table Tree struct searchTable { char first[10]; int first_id; char second[10]; int second_id; …
Goldengirl
  • 957
  • 4
  • 10
  • 30
3
votes
3 answers

Adding specific letters to a string MATLAB

I'm a neuroscience/biomedical engineering major struggling with this whole MATLAB programming ordeal and so far, this website is the best teacher available to me right now. I am currently having trouble with one of my HW problems. What I need to do…
Jessica Marie
  • 293
  • 5
  • 16
3
votes
3 answers

Strcat stack smashing behaviour

When running the following intentional stack smashing code, strcat copies the value of source exactly ten times. #include #include int main() { char a[16]; char b[16]; char c[32]; strcpy(a,…
Forest
  • 33
  • 4
3
votes
3 answers

strcat() crashes if using same array as both parameters

char r[40]; strcpy(r,"abcdef"); strcat(r,r); My program crashes at the third line? Replacing strcat(r,r); by strcat(r,"abcdef"); works fine though.... why is that?
user1420563
  • 195
  • 1
  • 12
3
votes
6 answers

adding space in strcat

I have two strings char str1[41] e char str2[41]. If I use strcat function to concatenate them I get an unique string without space instead I would have space between these. this could be a way: strcat(strcat(str1, " "),str2) Does it exist another…
Mazzy
  • 13,354
  • 43
  • 126
  • 207
3
votes
3 answers

strcat() implementation works but causes a core dump at the end

My implementation of strcat(char*, const char*) seems to work but then it causes a core dump. strcat() implementation: char* strcat(char* dest, const char* src) { char* tmp = dest; while(*tmp) ++tmp ; while( (*tmp++ = *src++ ) != '\0')…
Davlog
  • 2,162
  • 8
  • 36
  • 60
3
votes
4 answers

Most efficient way to use strcat() with a string and int?

I'm try to concatenate to char * rv with the result of a function call that will return an int. fib() returns an int. The main problem I'm running into is that strcat()'s signature requires a const char * as it's second arg: char * strcat ( char *…
iaacp
  • 4,655
  • 12
  • 34
  • 39
3
votes
1 answer

Implementation of strcpy and strcat that get a reference of a pointer bug

Possible Duplicate: Any better suggestions for this c functions copyString,concatString This is a question form a job interview , I need to implement it with a specific signature this is the code I need to work: int main(int argc, char…
user1120007
  • 268
  • 3
  • 13
1 2
3
35 36