d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Mvs 2010 - Calloc W/ Structs
Add Reply New Topic New Poll
Member
Posts: 106
Joined: May 16 2009
Gold: 25.55
Nov 1 2013 04:52pm
Here is my problem.
I'm using calloc (can switch it to malloc) to make a struct into a malloc array. The value of the array comes from the input.txt file. However, i get an a few errors using Microsoft Visual Studios 2010
'auctions': illegal use of this type as an expression
'auc_val': undeclared identifier

TEXT FILE
Code
15 25 200
3 10
17.99 22.99 109.99


C CODE
Code
// INCLUDES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// STRUCTS
typedef struct{
double price;
int bidder;
}auctions;


// FUNCTIONS


// MAIN
int main(){
// VARIABLES
//other
int i;

//tickets
double presale_cost, door_cost;
int presale_sold;

//auctions
double auction_price, auction_incro;
int auction_items;

// END VARIABLES

FILE * fi = fopen("auction.txt","r");

//tickets in
fscanf(fi,"%lf %lf %i",&presale_cost, &door_cost, &presale_sold);


//auctions in
fscanf(fi,"%i %lf",&auction_items, &auction_incro);
auctions *auc_val = (auctions*)calloc(auction_items,sizeof(auctions));


fcloseall();
system("pause");
return 0;
}
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Nov 1 2013 06:52pm
'auctions': illegal use of this type as an expression
auctions type is wrong

'auc_val': undeclared identifier
this is undefined
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 1 2013 07:02pm
Try doing

Code
auctions *auc_val = (auctions*)calloc(auction_items,sizeof(*auc_val));
Member
Posts: 106
Joined: May 16 2009
Gold: 25.55
Nov 2 2013 02:34am
Still doesn't work. I'm not entirely sure why this doesn't work because using c99 strict on compileonline.com this works. However; using Microsoft Visual Studios this doesnt work.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Nov 2 2013 03:07am
is it a .c file?

I found this on stackoverflow:

Quote

If you compile a file that has the .c extension, VS will use it's C compiler. However, you should be aware that said C compiler isn't C99 conformant (or even C89 for some cases, if I remember correctly). Visual Studio is not really a C compiler, it's C++ mostly. You will have to use a C++ project and simply include .c files.


one such case is declaring variables in the middle of a code block iirc.

This post was edited by Eep on Nov 2 2013 03:08am
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll