Results 1 to 9 of 9

Thread: array of string operation

  1. #1

    array of string operation

    how do we find the string length without using strlen() function?


  2. #2
    Expert Member
    Join Date
    Sep 2006
    Answers
    477

    Re: array of string operation

    There are many ways of doing it. Just running through the characters of the string inside a for/while loop will do the trick.

    Cheers!
    Kalayama

    [COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]

    Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"

  3. #3
    Junior Member
    Join Date
    Aug 2007
    Answers
    2

    Re: array of string operation

    char ch[20];
    int i=0,len=0
    //enter string and store it a array;

    while(ch[i]!='\0')
    { len=len+1;
    i++;
    }
    cout<<"length is" <<len;


  4. #4
    Junior Member
    Join Date
    Jul 2007
    Answers
    20

    Re: array of string operation

    #include<stdio.h>
    #include<conio.h?
    void main()
    {
    char ch[20];//to store string into the arry
    int i=0,length=0
    while(ch[i]!='\0')// while arry not equal to null. String stores at the end as null
    {
    length+=1;//length=length+1
    i++;
    }
    printf("The String length is",length);
    }


  5. #5
    Junior Member
    Join Date
    Nov 2007
    Answers
    2

    Re: array of string operation

    Quote Originally Posted by sagar123 View Post
    char ch[20];
    int i=0,len=0
    //enter string and store it a array;

    while(ch[i]!='\0')
    { len=len+1;
    i++;
    }
    cout<<"length is" <<len;
    could you please tell , what for len is used ............ without len we can get the ans


  6. #6
    Junior Member
    Join Date
    Jul 2007
    Answers
    20

    Re: array of string operation

    len is used for find the length of the string


  7. #7
    Junior Member
    Join Date
    Nov 2007
    Answers
    5

    Re: array of string operation

    char *ch;
    gets(ch);
    for(int i=0;ch[i]!='\0';i++);
    printf("%d",i);


  8. #8
    Junior Member
    Join Date
    Nov 2007
    Answers
    2

    Re: array of string operation

    To find length of an array use this

    int a;

    a=printf("12345");

    /* a has length of string "12345" i.e 5


  9. #9
    Junior Member
    Join Date
    Nov 2007
    Answers
    2

    Re: array of string operation

    [QUOTE=shivaram.cunchala;12881]how do we find the string length without using strlen() function?[/QUOTby counting the number of character with spaces


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact