Got another prg: write a program to concatenate 2 strings. Apart from usin strcat, is there another simple way of doing it?
Got another prg: write a program to concatenate 2 strings. Apart from usin strcat, is there another simple way of doing it?
>Apart from usin strcat
Yes, do your own version of strcat.
Loading.....
( Trying to be a good C Programmer )
My version is not working. that's why i asked for another version.
Code:#include "stdio.h" #include "conio.h" #define N 30 main() { char *str,*str1,temp; int i=0,j=0,k,flag; char x[N]; clrscr(); printf("Input a string: "); scanf("%s",str); printf ("\n"); printf("Input 2nd string: "); scanf("%s",str1); printf ("\n"); while(*(str+i)!='\0') { i++; } printf("%d", i); while(*(str1+j)!='\0') { j++; } printf("%d", j); while (i<=0) { x[k]=*(str+i); printf("%c", *(str+i)); i++; } while (k<=0) { x[k]=*(str+k); printf("%c", *(str+k)); k++; } }
i've changed it but still it isn't working...
Code:k=0; while (i>=0 && *(str+i)!='\0') { x[k]=*(str+i); printf("%c", *(str+i)); i++; k++ }
This one won't work either.Code:while (k<=0) { x[k]=*(str+k); printf("%c", *(str+k)); k++; }
You can write:
The while statement you posted in your last post doesn't need the condition i >= 0Code:while( *str1 != '\0' ); { x[k] = *str1++; printf( "%c", x[k] ); k++; }
Also, if you want to use the variable i, you have to initialize i to 0 ( for that loop ).
And at the end append the null character at the end of x[]
Loading.....
( Trying to be a good C Programmer )