string

Discussion in 'C' started by fmmctg01, Apr 2, 2011.

  1. fmmctg01

    fmmctg01 New Member

    Joined:
    Mar 31, 2011
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    strcpy, strcat and printf are your friends.
     
  3. teacher

    teacher New Member

    Joined:
    Mar 27, 2011
    Messages:
    66
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    i hate jobs
    Location:
    india,agra
    Home Page:
    http://www.crazylearner.in
    you can write the code without the use of these functions....
    Code:
    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..
     
    fmmctg01 likes this.
  4. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28


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

    teacher New Member

    Joined:
    Mar 27, 2011
    Messages:
    66
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    i hate jobs
    Location:
    india,agra
    Home Page:
    http://www.crazylearner.in
    oh sorry....
    i just forget here is the updated version....
    Code:
    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?
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You missed the i in the int main line.
     
  7. teacher

    teacher New Member

    Joined:
    Mar 27, 2011
    Messages:
    66
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    i hate jobs
    Location:
    india,agra
    Home Page:
    http://www.crazylearner.in
    he he really guys its feel like i am sitting between experts and it feels very good
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice