Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   string (http://www.go4expert.com/forums/string-t25407/)

fmmctg01 3Apr2011 02:10

string
 
char str1[100]="a rolling stone";
char str2[200]="gather no moss";
char str3[100];
write code that content of str1,followed by the content of str2, into str3. Display str3.

xpi0t0s 4Apr2011 21:46

Re: string
 
strcpy, strcat and printf are your friends.

teacher 5Apr2011 20:30

Re: string
 
you can write the code without the use of these functions....
Code: cpp

int main(){
int i,j;
char str1[100]="a rolling stone";
char str2[200]="gather no moss";
char str3[100];
for(i=0;str1[i]!='\0';++i)
str3[i]=str1[i];
str3[i]='  ';
for(j=0;str2[j]!='\0';++j)
str3[j+i+1]=str2[j];
str3[j+i+1]='\0';
printf("%s",str3);
}

but i suggest you to apply your brains in this.This is a very simple programming question..

virxen 7Apr2011 22:29

Re: string
 
Quote:

Originally Posted by teacher (Post 81521)
you can write the code without the use of these functions....
Code: cpp
int main(){
int i,j;
char str1[100]="a rolling stone";
char str2[200]="gather no moss";
char str3[100];
for(i=0;str1[i]!='\0';++i)
str3[i]=str1[i];
str3[i]=' ';
for(j=0;str2[j]!='\0';++j)
str3[j+i+1]=str2[j];
str3[j+i+1]='\0';
printf("%s",str3);
}


but i suggest you to apply your brains in this.This is a very simple programming question..

the code you gave is wrong check it again.(Hint 100+200>100)

teacher 7Apr2011 22:52

Re: string
 
oh sorry....
i just forget here is the updated version....
Code: cpp

nt main(){
int i,j;
char str1[100]="a rolling stone";
char str2[200]="gather no moss";
char str3[305];
for(i=0;str1[i]!='\0';++i)
str3[i]=str1[i];
str3[i]=' ';
for(j=0;str2[j]!='\0';++j)
str3[j+i+1]=str2[j];
str3[j+i+1]='\0';
printf("%s",str3);
}


anything else?

shabbir 8Apr2011 08:22

Re: string
 
Quote:

Originally Posted by teacher (Post 81639)
oh sorry....
i just forget here is the updated version....
Code: cpp

nt main(){
int i,j;
char str1[100]="a rolling stone";
char str2[200]="gather no moss";
char str3[305];
for(i=0;str1[i]!='\0';++i)
str3[i]=str1[i];
str3[i]=' ';
for(j=0;str2[j]!='\0';++j)
str3[j+i+1]=str2[j];
str3[j+i+1]='\0';
printf("%s",str3);
}


anything else?

You missed the i in the int main line.

teacher 8Apr2011 08:56

Re: string
 
he he really guys its feel like i am sitting between experts and it feels very good


All times are GMT +5.5. The time now is 22:07.