Re: Arrays..and arguments
Quote:
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