0

i have a 2d array that's array[10][10] and a double number. I want to put that number into the 1st line of the array how will i do that?

array[0]=number; does not work, is there a simple way of converting it?

for instance

double number;
double list[10][10]
number=5.35
i want to make
list[0] = 5.35 basically filling the first line. Please help, thanks

Heres the code that i tried

#include <stdio.h>

int main ()
{
char word[10][10];
double num;
double number[10][10];
FILE*myin;
myin=fopen("first.dat","r");
fscanf(myin,"%s",&word[0]);
fscanf(myin,"%lf",&num);
printf("%s\n%lf",word[0],num);
number[0]=num;
fclose(myin);
return(0);
}

Edited by jackc121: n/a

4
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by jackc121
0

i'm still confused, the thread sets an array = to another array, what i want to do is set an array = to a (double) number

0

If what you mean is that you want to fill list[0][0] through list[0][9] with 5.35f, then use a for loop and assign 5.35f to each int from 0 through 9 on row 0.

0

You define the TWO 2D arrays, but then you handle them like 1D vectors. Is that what you want to do?

double number[10][10];

. . .

number[0]=num;

. . .

If you want to assign num to array element (0,0), you should state it like this:

number[0][0]=num;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.