Find the answer to your Linux question:
Results 1 to 3 of 3
Hi friends, Is there any inbuilt function other than strncmp which can evaluate a string as given below, array[10]={""}; --> has no values array[10]={" "}; --> contains 12 spaces array[10]={"1234567890"}; ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    30

    Lightbulb Function to validate a string with space


    Hi friends,
    Is there any inbuilt function other than strncmp which can evaluate a string as given below,
    array[10]={""}; --> has no values
    array[10]={" "}; --> contains 12 spaces
    array[10]={"1234567890"}; --> contains 12 char values
    array[10]={"a3cvvae3"}; --> contains alp-num values

    my requirement is " if all 10 values are spaces print 1 else if it contains some values print 2 else print 3.

    if i use strlen, even space is counted !

    I know that i can evaluate using for loop by checking 1 by 1 char, and using strcmp function, is there any other way ??


    Thanks
    Jayasekar

  2. #2
    Just Joined!
    Join Date
    Jul 2010
    Posts
    53
    Code:
    i = memcmp(array,"          ",10)==0 ? 2 : array[0]=='\0' ? 3 : 1 ;

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,508
    Please don't post class problems here! Your initializers are really bogus and you need to learn why...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •