473,379 Members | 1,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

pls check it..(MACRO)

# include <stdio.h>
# define MYMAC(MY) MY //Macro Function

void main()
{
char s[10]="3+2-(4*1)/5";
printf("Result : %f",MYMAC(s)); ??Macro Call
}



Guys i need a clarification abt why the above code is not working.. actually the work of macro is to paste its content at the desired place where we call them.. is it?
if so, when i call the
printf("Result : %f",MYMAC(s)); ??Macro Call
Macro, why didn't it is pasting the expression as,
printf("Result : %f",3+2-(4*1)/5); and work.

urgent ya.. please....
Oct 4 '06 #1
5 2067
tyreld
144 100+
There are two problems here.

1.) You haven't declard your character array large enough to hold all of the characters you are trying to initialize it with. Your string expression has 11 characters in it, but your character array only has room for 10. You also need to keep in mind that literal strings will have a null terminating byte (ie. '\0') appended to the end of the string. So, you need to provide storage for 12 characters.

2.) You are using "%f" in your printf statement which is used for printing a floating point value. You need to supply a "%s" instead to print a string.
Oct 4 '06 #2
Banfa
9,065 Expert Mod 8TB

# define MYMAC(MY) MY //Macro Function

if so, when i call the
printf("Result : %f",MYMAC(s)); ??Macro Call

Macro, why didn't it is pasting the expression as,
printf("Result : %f",3+2-(4*1)/5); and work.
macros do a string substitution. When the preprocessor encounters them it replaces them with there definition.

At this line of code the preprocessor finds the macro MYMAC and performs it's string substitution.

printf("Result : %f",MYMAC(s));

You have defined the macro as

# define MYMAC(MY) MY //Macro Function

so

MYMAC(MY) --> MY

so

MYMAC(s) --> s

so the statement ends up as

printf("Result : %f",s);
Oct 4 '06 #3
macros do a string substitution. When the preprocessor encounters them it replaces them with there definition.

At this line of code the preprocessor finds the macro MYMAC and performs it's string substitution.

printf("Result : %f",MYMAC(s));

You have defined the macro as

# define MYMAC(MY) MY //Macro Function

so

MYMAC(MY) --> MY

so

MYMAC(s) --> s

so the statement ends up as

printf("Result : %f",s);
thanks for sparing your time... can't i make that code to evaluate the expression.. sorry for not minding abt the size of array.. lets ignore the size.. i need the expression part.. let the size of array be 80.. pls find some solution for me guys.. HOW TO MAKE THE CODE WORK AS EXPRESSION EVALUATOR.. CAN I ??
Oct 4 '06 #4
Banfa
9,065 Expert Mod 8TB
HOW TO MAKE THE CODE WORK AS EXPRESSION EVALUATOR.. CAN I ??
Only by writing a function that will parse the string by looking at each character in turn and taking appropriate action.

You will not be able to write a macro that evaluates a string in this mannor.
Oct 4 '06 #5
Only by writing a function that will parse the string by looking at each character in turn and taking appropriate action.

You will not be able to write a macro that evaluates a string in this mannor.
THANK YOU YAAR... THAKS A LOT
Oct 4 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Richard Meister | last post by:
Hi, I'd like to define several constants and make sure that all of them are smaller than a given other constant. I thought this could be done by a simple macro. Something like this: #define...
1
by: ParkMan | last post by:
Hello, I am trying to open a Word template, fill some fields, and mark some check boxes as checked. Here is the code I am using: ' Launch Word and load the report template Set objWord = New...
7
by: rytsyd | last post by:
what should be the syntax of a macro condition if I want to check if the table name is already existing? I need this condition so that if the table name is existing, the macro will perform other task...
1
by: Cesar Zapata | last post by:
Hi, I have a a bound subform and what i'm trying to do is do check if some criteria applies before saving the record and trigger a macro. basically this is what I got. Date Received ...
4
by: joemo2003 | last post by:
Is there a way to use VBA check to see the macro security setting? I want to use VBA check to see is the "Trust access to VB project" setting is on? Such as it return "True" when set to Trust access...
14
by: Martin Wells | last post by:
When I have errors in a program, whether they be compiler errors, linker errors, or if the program crashes when running, I have a list of things I check for initially. If I get an error for...
2
by: kevcar40 | last post by:
Hi is it posible to check if another database is open? i have several datasbase the first is a dbase where the local data is maintained on closing the database the table is exported to a holding...
10
by: Cliff72 | last post by:
Is there a way in VBA to check if a linked table in the database has been updated? Example: I have a table "LedgerTemp" which is a direct link to a text file on the LAN "Ledger.txt" This text...
173
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc....
13
by: Guillaume Dargaud | last post by:
Hello all, I tried to write a macro to check if a system is big endian or little endian with no success. Don't get me wrong, I have no problem writing a function or a one liner to do that, but I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.