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

if statement compilation in c

hi,
i'm new to C language, and i'm having a problem compiling the following code:
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.  
  4.     int *b = NULL;
  5.  
  6.     b = (int *)malloc(sizeof(int));
  7.  
  8.     if (b == NULL)
  9.     {
  10.         printf("Error");
  11.     }
  12.  
  13.     int new_int;
  14.  
  15.  
  16.     return 0;
  17.  
  18. }
  19.  
i'm getting a the following error :
error C2143: syntax error : missing ';' before 'type'
on the "int new_int;" line.
what is the problem?
thanks.
Aug 17 '07 #1
3 1194
ilikepython
844 Expert 512MB
hi,
i'm new to C language, and i'm having a problem compiling the following code:

int main()
{

int *b = NULL;

b = (int *)malloc(sizeof(int));

if (b == NULL)
{
printf("Error");
}

int new_int;


return 0;

}

i'm getting a the following error :
error C2143: syntax error : missing ';' before 'type'
on the "int new_int;" line.
what is the problem?
thanks.
I'm not sure what the problem is, but, this compiles on Dev-C++ 4.9.9.2.
Aug 17 '07 #2
JosAH
11,448 Expert 8TB
I'm not sure what the problem is, but, this compiles on Dev-C++ 4.9.9.2.
Yep, but according to the topic title that is supposed to be C, not C++. C doesn't
allow the definition of new local variables in the middle of a block.

kind regards,

Jos
Aug 17 '07 #3
ilikepython
844 Expert 512MB
Yep, but according to the topic title that is supposed to be C, not C++. C doesn't
allow the definition of new local variables in the middle of a block.

kind regards,

Jos
Ah, I see, I had no idea about that, sorry.
Aug 17 '07 #4

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

Similar topics

3
by: Matt | last post by:
When the ASP statement end with a _ character, then the next line cannot have comment ' character. Is that correct? Since I encountered the following error: Microsoft VBScript compilation...
2
by: Sune | last post by:
Hi, I need to do a loop with some criterias that depends on an earlier database query. I tried to do it this way, but it seems not to accept that the do is inside the if: if not objrs.EOF...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
10
by: Sune | last post by:
Hi, previously I used Eclipse CDT for compiling my files just to get started with C and leave C++ behind. Now it's time to get a little more serious so I've moved my files to a new workplace and...
2
by: Macca | last post by:
Hi, I have a switch statement that has 5+ case statements. Each of these case statements copies form one array to another. Rather than doing a separate try..catch statement for each case...
10
by: Zen Masta | last post by:
Original code: <% img_name=rs("ISBN") & ".jpg" if CheckPath(img_name)=true then%> <IMG src="../images/70pixelsTall/<%=rs("ISBN")%>.jpg" width="50" height="70" border=0> <% else %> <img...
26
by: a.mil | last post by:
I am programming for code-speed, not for ansi or other nice-guy stuff and I encountered the following problem: When I have a for loop like this: b=b0; for (a=0,i=0;i<100;i++,b--) { if (b%i)...
7
by: siocodes | last post by:
I know I am so close on this, but I cannot see what the syntax fix is. I am sending two e-mails via one asp page; one to the gift giver and one to the recipient...I originally had the message text in...
3
by: Indy | last post by:
Hi, I am new to VB and have some previous programming experiences. Curently working as an IT support person and trying to write a VB 6 script to access apos database and get one of the table's...
3
by: Eric Davidson | last post by:
DB2 9.5 I keep geting the message. SQL0101N The statement is too long or too complex. SQLSTATE=54001 When one of my sql statements takes over 60 seconds to compile the sql statement. Is...
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
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...
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
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.