Inputting data into an array of structures C++

So my probelm is as the title says. I need to fill up the stocklist array with data in putted from the keyboard. My code runs, but crashes after I enter data for the first member of the stocklist array…
Attached screen shots and code.
Any help is appreciated, thanks!

Code:

#include “stdio.h”
#include “string.h”

const int IDLEN=10;
const int POLARITYLEN=3;
const int MAXSTOCKITEMS=10;

struct TransistorRec {
char manufacturersID[IDLEN+1];
char polarity[POLARITYLEN+1];
float power;
float gain;
int stock;
};
typedef struct TransistorRec Transistor;

struct StockRec{
int size;
Transistor stocklist[MAXSTOCKITEMS];
};
StockRec Stock;

void insert(void);
void print(void);

int main()
{
insert();
print();

return 0;}

void insert(void)
{
int i = 1;
for (i=1;i<11;i++)
{
printf(“Input details: “);
scanf(”%s %s %f %f %d”, Stock.stocklist[i].manufacturersID, Stock.stocklist[i].polarity, Stock.stocklist[i].power, Stock.stocklist[i].gain, Stock.stocklist[i].stock);
}

}
void print(void)
{
int j = 1;
for (j=1;j<11;j++)
{
printf(“Transistor %d: %s %s %f %f %d\n”, j, Stock.stocklist[j].manufacturersID, Stock.stocklist[j].polarity, Stock.stocklist[j].power, Stock.stocklist[j].gain, Stock.stocklist[j].stock);
}
}


So it fails at the scanf() function?

You could try to use the more native functions, like cout or cin (unless you were told to / have a good reason to). e.g.

for(int i = 0; i < 10; i++) {
    cout << "Input details: ";
    cin >> Stock.stocklist[i].manufacturersID;
    cin >> Stock.stocklist[i].polarity;
    cin >> Stock.stocklist[i].power;
    cin >> Stock.stocklist[i].gain;
    cin >> Stock.stocklist[i].stock;
}

There are a couple of other things as well... For instance, the stocklist array will be length 10, so it should start at index 0 (since that's where arrays start) and end at 9, so i < 10 or i <= 9. On top of that, you should just initialize the loop variable in the initialization of the for loop it gives you, like I did, instead of outside, since you're not using it outside. It makes it a little more concise. Same for the second function / for loop.

Yep that did it! Thanks heaps for that, I've never used the iostream header before but after a bit of fiddling I got it working :)
The mystery about why scanf wasn't working is for another day!

You need to pass your arguments to scanf as pointers.

scanf("%s %s %f %f %d", Stock.stocklist[i].manufacturersID, Stock.stocklist[i].polarity, &Stock.stocklist[i].power, &Stock.stocklist[i].gain, &Stock.stocklist[i].stock);

is correct.

Read
http://en.cppreference.com/w/cpp/io/c/fscanf (and also bookmark http://en.cppreference.com/, it is very useful).

You do not need to do this this for your char array arguments (Transistor::manufacturersID and Transistor::polarity) because in C/C++ the name of an array is equivalent to the address of it's first element:

char my_char_array[64];
assert(my_char_array == &my_char_array[0]);

Read

Now we have that sorted, I was wondering - is this part of a class, and if so, are you being taught C or C++? They are actually different languages (although closely related) and in my opinion the code you have written is C, not C++ (as it uses no C++ features).

I ask because I would happily give you some tips on how to write this as much better formed C++ code, but I don't want to tell you loads of stuff you can't possibly know (as far as your lecturer is concerned) :).

Ah yes I'm still getting my head around pointers but I've made a fair bit of progress in the last couple of days so what you said makes a lot of sense, thanks for that :)
Yes this is for a class, the class is on mainly C but the lecturer will talk talk about C++ quite a bit. So you are probably right that this code is more C than C++.
Thanks for the offer, but I'm sure as the semester progresses I will become more proficient in C++ :)