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
1 answer

Using strcat() to concatenate two values gathered from void functions

I am trying to concatenate two values that are returned from two different functions, a Server IP Address and a Student ID. The functions used to get these have been void function in order to access the server. I am wanting to use strcat() function…
-3
votes
1 answer

Why does "strcat" on an array cause overwriting?

strcat(argv[1], ".txt"); puts(argv[1]); strcat(argv[2], ".txt"); puts(argv[2]); puts(argv[1]); Say the first([1]) argument is called "a" and the second([2]) "b". This code gives the following output: a.txt txt.txt a.txt.txt Why is this happening??…
Hedhed
  • 33
  • 6
-3
votes
4 answers

Why after using strcat function original string changed?

well i have two char array . when i try to concatenate both string using strcat function. Then my string "a" length reduced from 9 to 6. i also lost my string "a" .string b changed too.See in the output. why this is happening ??? here is what i…
Rakesh Sharma
  • 39
  • 1
  • 7
-3
votes
2 answers

strcat() in c language programming

when I run this code I always found a problem in my IDE. Can you give this solution ? #include #include int main(void) { char cname[4]="mahe"; strcat(cname, "Karim"); printf("%s",cname); getch(); return…
Mahe Karim
  • 49
  • 1
  • 10
-3
votes
1 answer

Printing space between strings when using strcat() function

How to print a space between two strings using strcat() function in c language?
Naveen
  • 34
  • 3
-3
votes
3 answers

How to concatenate a name of file using fopen function?

I want to create a file with a a prticular extension added after the supplied name. I create this code: void create_file(char name[],char user[],char date[]){ FILE* fichier=NULL; fichier=fopen(strcat(name,".txt"),"a+"); …
arrow man
  • 51
  • 2
  • 11
-3
votes
1 answer

Does strcat() return an error as strcat_s() does?

Does strcat() return an error as strcat_s() does? Can strcat() replace strcat_s()`? char str1[50] = "To be, or not to be, "; char str2[] = "that is the question."; int retval = strcat_s(str1, sizeof str1, str2); if(retval) printf("There was…
viki
  • 1
  • 1
-3
votes
1 answer

difficulties using getchar for arrays C

This is my code.i want to extend this code to ask user to enter name,address,phone and town and print it out.i did the main parts declerations etc but while using getchar i have some difficulties.what to do? #include #include…
hlap
  • 11
  • 1
-4
votes
1 answer

Why strcat() causes causes segmentation fault in the fallowing code?

Why the below code results in segmentation fault? #include #include int main () { char *name="Kaveri"; char *rd="Rajshekhar"; strcat(name,rd); puts(name); return 0; }
-4
votes
1 answer

single char strcat -C

I want to put two single char together. Should I use the function strcat? the following is my code int main(){ char *a[4]={"1","2","3","4"}; char *new_a[2]; for (i=0;i<2;i++){ new_a[i]=strcat(a[2*i],a[2*i+1]); …
yuyu
  • 1
  • 1
-4
votes
1 answer

Does strcpy or strcat make unnecessary changes of the string when used within printf statement?

I ran this code: #include #include int main() { static char str1[] = "dills"; static char str2[20]; static char str3[] = "Daffo"; int i,j; i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills"); printf("%d",…
Arnab
  • 19
  • 2
-4
votes
3 answers

Not returning string. This program converts digit like 123 to words like "One Two Three", why in the end I am not getting anything?

#include #include char *int_to_string( int n ); void main() { int n; printf("Enter the number : "); scanf("%d",&n); printf("\n%d in words is : %s.\n",n,int_to_string(n)); } char *int_to_string( int n) { …
Gaurish Gangwar
  • 395
  • 4
  • 14
-4
votes
2 answers

passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]

I am reading off a fifo, and then I try to make a another array in different format out of it. I know buf gets its values as expected, since printing it out is good. char graphic[100]; char buf[100]; read(fd_read,&buf,50); for(int i=0; i<10;…
aviadm71
  • 53
  • 1
  • 9
-4
votes
1 answer

Strcat(a[1],"22") how to use? C programming

i'm trying to make a program that if the previous letter is the same with the current letter that will be outputed will put a space between them... #include #include #include #define T 100 #define S 255 int main(){ char…
HerlDerp
  • 47
  • 1
  • 1
  • 11
-4
votes
1 answer

How to strcat with intervals in C++?

So here's my code: #include #include using namespace std; const int MAX_SIZE1 = 20; const int MAX_SIZE2 = 10; int main() { char a[MAX_SIZE1][MAX_SIZE1][MAX_SIZE2]; int n, i, j; cin >> n; for (i = 0; i < n;…
user3213110
  • 199
  • 4
  • 14
1 2 3
35
36