d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C Program > Lookin For Some Help
Add Reply New Topic New Poll
Member
Posts: 2,724
Joined: Sep 23 2012
Gold: 300.00
Oct 9 2015 11:07am
Im trying to create an array based on the user input of needed columns and then prompt the user to input values to fill up the array. every time i try to do


printf("please enter the number of columns: ")
scanf("%f", &n)

a[4][n] = 1



the compiler gives me an error saying that "n" is not an integer.

*not full code just the section im having trouble with

This post was edited by holychikenz on Oct 9 2015 11:32am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 9 2015 05:20pm
isn't %f float? what datatype is n defined as?
Member
Posts: 3,476
Joined: Jul 20 2015
Gold: 651.00
Oct 14 2015 07:50am
try using "%d" instead of "%f"
Member
Posts: 4,613
Joined: Sep 24 2013
Gold: 21,779.91
Oct 28 2015 06:52am
Quote (holychikenz @ 9 Oct 2015 19:07)
Im trying to create an array based on the user input of needed columns and then prompt the user to input values to fill up the array. every time i try to do


printf("please enter the number of columns: ")
scanf("%f", &n)

a[4][n] = 1



the compiler gives me an error saying that "n" is not an integer.

*not full code just the section im having trouble with



array index can only be an integer

int *n;

%d
Member
Posts: 2,850
Joined: Dec 18 2009
Gold: 4.74
Nov 1 2015 10:58am
nope
Member
Posts: 10,797
Joined: Aug 3 2009
Gold: 6,709.00
Nov 1 2015 06:05pm
my head hurts :wallbash:
Member
Posts: 31,523
Joined: Mar 31 2004
Gold: 6.57
Nov 10 2015 01:25am
please post your hole problem

you cant just have user enter in values into array and load them 1 at time each time excutes it will just write into Slot 0 of array so you need to write a loop to step threw array.. Also you should put in dummy checker that if array is filled it creates new array copies it over than destroys old array.. So you dont get array out of bounds.. it looks like your making a 2 demontal array ... if you post hole Program I can help
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll