Arrays..and arguments

This is a discussion on Arrays..and arguments within the C Programming forums, part of the General Programming Boards category; Hi can someone please help me? I have to place the following strings "pow", "sin","exp", "cos" in the array recieved ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    6

    Smile Arrays..and arguments

    Hi can someone please help me?

    I have to place the following strings "pow", "sin","exp", "cos" in the array recieved as argument.


    /*
    * getop.c
    *
    * gets next token: operator or numeric operand
    */

    #include <stdio.h>
    #include <ctype.h>
    #include "calc.h"

    #define FCT '1' //$$ Returns a new symbolic constant

    int getop(char s[])
    {
    int i, c;

    while ((s[0] = c = getch()) == ' ' || c == '\t')
    ;

    s[1] = '\0';

    if (!isdigit(c) && c != '.')
    return c; /* not a number */


    ********Modified part of code************

    string p = "pow";
    string e = "exp";
    string s = "sin"; // Is this the correct way?
    string c = "cos";

    if( s[i] == p || s[i] ==e || s[i] == s || s[i] ==c)
    return FCT;

    *************************************


    /* collect integer part in string s */
    i = 0;
    if (isdigit(c))
    while (isdigit(s[++i] = c = getch()))
    ;

    /* collect fractional part in string s */
    if (c == '.')
    while (isdigit(s[++i] = c = getch()))
    ;

    s[i] = '\0';
    if (c != EOF)
    ungetch(c);

    return NUMBER;
    }

  2. #2
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284

    Re: Arrays..and arguments

    Originally posted by fanaonc
    Hi can someone please help me?

    I have to place the following strings "pow", "sin","exp", "cos" in the array recieved as argument.


    /*
    * getop.c
    *
    * gets next token: operator or numeric operand
    */

    #include <stdio.h>
    #include <ctype.h>
    #include "calc.h"

    #define FCT '1' //$$ Returns a new symbolic constant

    int getop(char s[])
    {
    int i, c;

    while ((s[0] = c = getch()) == ' ' || c == '\t')
    ;

    s[1] = '\0';

    if (!isdigit(c) && c != '.')
    return c; /* not a number */


    ********Modified part of code************

    string p = "pow";
    string e = "exp";
    string s = "sin"; // Is this the correct way?
    string c = "cos";

    if( s[i] == p || s[i] ==e || s[i] == s || s[i] ==c)
    return FCT;

    *************************************


    /* collect integer part in string s */
    i = 0;
    if (isdigit(c))
    while (isdigit(s[++i] = c = getch()))
    ;

    /* collect fractional part in string s */
    if (c == '.')
    while (isdigit(s[++i] = c = getch()))
    ;

    s[i] = '\0';
    if (c != EOF)
    ungetch(c);

    return NUMBER;
    }
    I

    string p = "pow";
    string e = "exp";
    string s = "sin"; // Is this the correct way?
    string c = "cos";
    In C89 you cannot delclare a variable anywhere except at the top of a block .
    There is no inbuilt string type in C , but the above code would be correct if string would have been defined as
    typedef char *string;
    even though I doubt you have done something like that as you do
    if( s[i] == p || s[i] ==e || s[i] == s || s[i] ==c)
    return FCT;
    s[i] is a character and p ?????!!!!!!!!

    two compare two strings in C use strcmp or strncmp

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    **this program has performed an illegal operation and will be shut down immediately**

    Please purchase any book on C. You won't regret it, I promise!
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arrays as function arguments :(
    By strokebow in forum C Programming
    Replies: 10
    Last Post: 11-18-2006, 02:26 PM
  2. Arrays as function arguments!
    By strokebow in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 01:32 PM
  3. dynamic multidimensional arrays as function arguments
    By magda_k in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2006, 03:00 PM
  4. multidimensional arrays as arguments
    By mrbiggs in forum C++ Programming
    Replies: 13
    Last Post: 12-31-2003, 07:33 AM
  5. Command line arguments and arrays
    By fatinez in forum C Programming
    Replies: 2
    Last Post: 09-12-2003, 02:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21