473,406 Members | 2,371 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,406 software developers and data experts.

How to remove syntex error from the followin code

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. #define pr (int n) printf("%d",n);
  5.  
  6. void main(void)
  7. {
  8.  
  9. int f;
  10.  
  11. scanf("%d",&f);
  12. pr(f);
  13. }
  14.  
Nov 25 '10 #1

✓ answered by Banfa

remove the int as well you can't type function like macro parameters

5 1528
donbock
2,426 Expert 2GB
It helps if you tell us what syntax error you're getting.

You define macro pr as not having any parameters, but then you try to pass it a parameter when you call it.
  • There can't be any spaces between the macro name and the open-parenthesis in the macro definition if you wish to define a macro that takes arguments.
  • A macro is not a function, you don't specify the types of the macro arguments in the macro definition.

If we make those corrections to your code we get this:
Expand|Select|Wrap|Line Numbers
  1. #define pr(n) printf("%d",n);
  2. void main(void)
  3. {
  4.   int f;
  5.   scanf("%d",&f);
  6.   pr(f);
  7. }
Which after macro substitution turns into this:
Expand|Select|Wrap|Line Numbers
  1. void main(void)
  2. {
  3.   int f;
  4.   scanf("%d",&f);
  5.   printf("%d",f);;
  6. }
Note the two semicolons on line 5. The first comes from the macro expansion, the second comes from your original source.

Consider what would happen here:
Expand|Select|Wrap|Line Numbers
  1. #define pr(n) printf("%d",n);
  2. ...
  3. if (flag)
  4.    pr(f);
  5. else
  6.    pr(g);
After macro substitution you get:
Expand|Select|Wrap|Line Numbers
  1. if (flag)
  2.    printf("%d",f);;
  3. else
  4.    printf("%d",g);;
which is logically equivalent to
Expand|Select|Wrap|Line Numbers
  1. if (flag)
  2.    printf("%d",f);
  3. ;
  4. else
  5. printf("%d",g);
  6. ;
It is considered bad form to include a command-terminating semicolon in a macro definition.
Nov 26 '10 #2
The error i get is "expression syntex error" when i call the macro in main function
Nov 26 '10 #3
Banfa
9,065 Expert Mod 8TB
remove the space between pr and ( in the #define
Nov 26 '10 #4
I tried removing space between pr and ( in #define but it gives another error. When i call pr in main function then it gives an error that pr must have prototype.
Nov 26 '10 #5
Banfa
9,065 Expert Mod 8TB
remove the int as well you can't type function like macro parameters
Nov 26 '10 #6

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

Similar topics

0
by: sql-db2-dba | last post by:
CLI connection failed. SQL0902C. A system error (reason code="6029321") occurred. Subsequent SQL statements cannot be processed. SQLSTATE=58005. Has anyone encountered the above error? We are...
1
by: Tom | last post by:
Suppose you have code structure like this: Option Explicit Dim MyVariable As Single Private Sub CallingProcedure() Call CalledProcedure() ....Do This ... End Sub Private Sub...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
3
by: JPARKER | last post by:
Our DB2 8.2 FixPak9 database running on Win2K crashed with after reporting this message SQL0902C A system error (reason code = 9") ocurred I have searched the DB2 documentation as well as the...
1
by: Nikhil Patel | last post by:
Hi all, I have the following code in the asp.net page added at runtime using RegisterStartupScript. But I get an error in the browser(syntex error-no details). DisplayLookupValues is a function...
3
by: Mark | last post by:
I'm just starting out in an introductory ASP.Net course, and am trying to run a simple program but keeping getting an error. "http://localhost/day1/listing0104.aspx" is placed in the address line...
1
by: scottrm | last post by:
I want to get the file name, line number etc. in error handling code in an asp.net application. I know how to trap errors in the Global.asax and I read that you can use the stack frame from the...
3
by: jonamukundu | last post by:
Hi everyone out there I have a rather funny problem. Error handling code routines do not seem to work on my laptop. I still get the default error messages when i test. One my desktop the code...
2
by: globomike | last post by:
Hi, can anybody tell me what the reason code 18 means in combination with a SQL0902 error? It would be helpful to know details about the reason code but I could not find any details about that...
1
by: sdanda | last post by:
When I build my application it gets this error.My application is sample "Error 1 Unable to copy file "obj\Debug\sample.exe" to "bin\Debug\sample.exe". The process cannot access the file...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.