By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

problems with Dev-C++

P: 1
Hi

I wrote this program ...

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #define size 3
  3.  
  4. main()
  5. {
  6.       int a[size];
  7.       int i;
  8.  
  9.       printf("Input values for array a\n");
  10.       for(i=0;i<size;i++)
  11.           {
  12.           printf("a[ %d ] = ",i);
  13.           scanf("%d",a[i]);
  14.           }
  15. }
  16.  
... and e always an get an Windows XP error message:
exp.exe has encountered a problem and needs to close. We are sorry for the inconvenience.

Can someone help me?
Thanks
Mar 14 '07 #1
Share this Question
Share on Google+
4 Replies


Banfa
Expert Mod 5K+
P: 8,916
You have 2 or 3 problems (depending on the file type C or C++)

1. main must return int. You have no choice in this matter, not returning int invokes undefined behaviour. And as a consequence of this you need to add a return statement.

2. If this is a C problem then main must have the parameters int argc, char ** argp

int main(int argc, char ** argp)

again not including them is undefined behaviour. If this is C++ then main can take no parameters.

3. And finally on the code line
Expand|Select|Wrap|Line Numbers
  1. scanf("%d",a[i]);
scanf requires a pointer to an int but you have provide an int meaning that it is almost certainly writing to some random memory location, this should be
Expand|Select|Wrap|Line Numbers
  1. scanf("%d",&a[i]);
Mar 15 '07 #2

Ganon11
Expert 2.5K+
P: 3,652
Banfa's 3rd suggestion is likely the one causing problems - earlier today, I was trying to use a C program and forgot to add the & before my variable in scanf, and I got the same error.

Guess that's what I get for trying to go backwards in time and learn C after C++ :P
Mar 15 '07 #3

Banfa
Expert Mod 5K+
P: 8,916
Banfa's 3rd suggestion is likely the one causing problems - earlier today, I was trying to use a C program and forgot to add the & before my variable in scanf, and I got the same error.

Guess that's what I get for trying to go backwards in time and learn C after C++ :P
I thought I told you not to bother with scanf?
Mar 15 '07 #4

Ganon11
Expert 2.5K+
P: 3,652
I was trying to see what was happening in a user's code! I had to do it just to see what was going wrong!
Mar 15 '07 #5

Post your reply

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