evaluate a string expression in if statement Linux C/C++ - C

This is a discussion on evaluate a string expression in if statement Linux C/C++ - C ; How can we evaluate a string expression in if statement Linux C/C++ -- comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must have an appropriate newsgroups line in your header for your mail to be seen, or the newsgroup name in ...

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

evaluate a string expression in if statement Linux C/C++

  1. Default evaluate a string expression in if statement Linux C/C++

    How can we evaluate a string expression in if statement Linux C/C++
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  2. Default Re: evaluate a string expression in if statement Linux C/C++

    "parul.prasad@wipro.com" wrote:
    >
    > How can we evaluate a string expression in if statement Linux C/C++


    By passing it to a function designed to evaluate it. What that
    does will depend on the definition of 'evaluate'.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  3. Default Re: evaluate a string expression in if statement Linux C/C++

    "parul.prasad@wipro.com" <parul.prasad@wipro.com> writes:
    > How can we evaluate a string expression in if statement Linux C/C++


    If your question were specific to Linux, it would be off-topic here.

    There is no such language as "C/C++". C and C++ are two separate (but
    related) languages. C is the only one we discuss here.

    Here's an example of evaluating a string expression in an if statement
    in C:

    #include <stdio.h>
    int main(void)
    {
    if ("string expression") {
    printf("ok\n");
    }
    return 0;
    }

    That answers the question you asked. I doubt that it answers the
    question that you *meant* to ask.

    You can expect slow feedback in this newsgroup, because articles have
    to be approved by the moderator before they can appear. You might
    have better luck in comp.lang.c, since I expect we'll need some
    back-and-forth discussion before we (a) figure out what you're asking,
    and (b) come up with a good answer.

    --
    Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  4. Default Re: evaluate a string expression in if statement Linux C/C++

    parul.prasad@wipro.com wrote:
    > How can we evaluate a string expression in if statement Linux C/C++


    It's not clear what you're trying to do. What do you mean by "evaluate
    a string expression?" If you're comparing two strings, for example,
    you'll want something like:

    if(strcmp(s1, s2) == 0) {
    puts("The strings are equivalent.");
    }
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  5. Default Re: evaluate a string expression in if statement Linux C/C++

    "parul.prasad@wipro.com" wrote:
    > How can we evaluate a string expression in if statement Linux C/C++


    It's not clear what you mean by that. C doesn't have "string expressions".
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  6. Default Re: evaluate a string expression in if statement Linux C/C++

    On 15 Nov 2006 05:19:29 GMT, "parul.prasad@wipro.com"
    <parul.prasad@wipro.com> wrote in comp.lang.c.moderated:

    > How can we evaluate a string expression in if statement Linux C/C++


    First, there is no language C/C++. There is C and there is C++, and
    we only discuss the former here.

    Second, before anyone can even begin to answer your question, you have
    to tell us what you mean by "evaluate a string expression". C doesn't
    actually have anything called a "string expression".

    The following code evaluates the length of a string in an if
    expression, but is probably not what you want:

    #include <string.h>

    int is_long_enough(const char *s)
    {
    if (strlen(s) > 10)
    return 1;
    else return 0;
    }

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c++-faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  7. Default Re: evaluate a string expression in if statement Linux C/C++

    parul.prasad@wipro.com wrote:
    > How can we evaluate a string expression in if statement Linux C/C++


    Without custom code, you probably can't.
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  8. Default Re: evaluate a string expression in if statement Linux C/C++

    On 15 Nov 2006 05:19:29 GMT, "parul.prasad@wipro.com"
    <parul.prasad@wipro.com> wrote:

    >How can we evaluate a string expression in if statement Linux C/C++


    First decide if you are going to code in C or C++. The two languages
    are not the same. If you want to use C++, this is not the correct
    newsgroup.

    Then explain what you mean by evaluate. There are numerous C
    functions which can process a string as part of an if expression.


    Remove del for email
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  9. Default Re: evaluate a string expression in if statement Linux C/C++

    parul.prasad@wipro.com wrote:
    > How can we evaluate a string expression in if statement Linux C/C++


    OK. So it's hard to understand what you mean - maybe a more elaborate
    question would have been clearer. However, as this is
    comp.lang.c.moderated, I'm going to ignore any c++ features and just
    talk about C strings.

    A C string is a bit wierd in that it is actually a pointer to some
    memory - all this "sometext" stuff is just to make initializing the
    memory easier if you need to say text.

    Thus if I go:

    char str[16];

    Then I've allocated a 16 char (probably 1 byte length each) long array
    on the stack. Saying

    str[7]

    is identical to

    *(str+7)

    Either will give us the 8th character in the array. The first is
    "special" syntax used by C for arrays it knows lots about. The second
    just treats str as a pointer to a char array, which is what it really
    is.

    Anyway, you want to "evaluate a string expression" "in an if". Well,
    that doesn't really make sense, as a string expression isn't really
    very boolean, but the meanings I can think of are:

    1) Test to see whether str is "true" or "false".
    How about:

    if( strcmp( str, "true" ) == 0 ) { return 1 }
    else if( strcmp( str, "false" ) == 0 ) { return 0 }
    else return -1;

    2) Test to see whether a string pointer is null ( you should do this
    before any of the other tests too, probably).

    if( str == NULL ) return -1;

    3) Test to see whether a string is "":

    if( str[0] == 0 ) return 0;
    OR
    if( strlen(str) == 0 ) return 0;

    4) Test to see whether two pointers are to the same string in memory
    (ie both at same buffer)

    if( str1 == str2 ) return 1

    5) Test to see whether the string arrays referred to by str1 and str2
    are the same

    if( ! strcmp( str1, str2 ) ) return 1;

    As you can see, you asked a really vague question. It's unlikely that
    people will always take the time to give you an answer to a question
    like this, and besides I might not be telling you what you need to know
    - I'm having to guess.

    In future, I'd suggest a longer question. I realise that English
    probably isn't your first language, so I understand that it costs more
    effort and might require 20 minutes with a dictionary. For that I
    apologise, but it seems that mailing lists are dominated by English
    speakers who can't cope with anything else. Like me

    I hope this reply is of some use,

    Rupert
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  10. Default Re: evaluate a string expression in if statement Linux C/C++

    On 15 Nov 2006 05:19:29 GMT in comp.lang.c.moderated,
    "parul.prasad@wipro.com" <parul.prasad@wipro.com> wrote:

    >How can we evaluate a string expression in if statement Linux C/C++


    Use a string function?

    --
    Thanks. Take care, Brian Inglis Calgary, Alberta, Canada

    Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
    fake address use address above to reply
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Can I evaluate an expression with the Eclipse debugger?
    By Application Development in forum Java
    Replies: 1
    Last Post: 12-13-2007, 12:38 PM
  2. Expression must evaluate to a node-set
    By Application Development in forum XML SOAP
    Replies: 2
    Last Post: 03-02-2007, 05:40 PM
  3. Expression Evaluate
    By Application Development in forum PROLOG
    Replies: 2
    Last Post: 11-10-2006, 12:33 AM
  4. How to evaluate in C# a string of expression
    By Application Development in forum Javascript
    Replies: 12
    Last Post: 02-09-2005, 10:25 AM