M
mdh
/***
I wonder if anyone can see why this is not working as planned
( concatenate n characters from t[] to s[]). I copy s[] to u[], then
add n characters to []u from t[]. When I debug, I see that u[] does
have the correct string, but when printed, it does not do so.
Thank you.
code below.
******/
#include <stdio.h>
# define SIZE 1000
int main () {
void strncat( char *s, char *t, int );
void strcpy(char *s,char *u);
int i=5;
char s[]="Now is the time for all good men";
char t[]="To be counted";
char u[SIZE];
strcpy(u, s);
strncat(u, t, i);
printf( "To the phrase: \"%s\"\n is added the first %d letters of the
phrase \"%s\"\n resulting in phrase: \"%s\" \n\n", s, i ,t, u);
return 0;
}
void strcpy(char *u, char *s){
while ( *u++ = *s++);
}
void strncat( char *u, char *t, int i){
while ( *u++);
while ( (*u++ = *t++) && i-- > 0 );
*u='\0';
}
I wonder if anyone can see why this is not working as planned
( concatenate n characters from t[] to s[]). I copy s[] to u[], then
add n characters to []u from t[]. When I debug, I see that u[] does
have the correct string, but when printed, it does not do so.
Thank you.
code below.
******/
#include <stdio.h>
# define SIZE 1000
int main () {
void strncat( char *s, char *t, int );
void strcpy(char *s,char *u);
int i=5;
char s[]="Now is the time for all good men";
char t[]="To be counted";
char u[SIZE];
strcpy(u, s);
strncat(u, t, i);
printf( "To the phrase: \"%s\"\n is added the first %d letters of the
phrase \"%s\"\n resulting in phrase: \"%s\" \n\n", s, i ,t, u);
return 0;
}
void strcpy(char *u, char *s){
while ( *u++ = *s++);
}
void strncat( char *u, char *t, int i){
while ( *u++);
while ( (*u++ = *t++) && i-- > 0 );
*u='\0';
}