473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

About double dimensional array initialisation

Hi everybody i want to know about array initialisation .
Today i was solving a problem and here is my code

#include<cstdio>
#include<cstring>
int l;
int div(char *a,int d)
{
int k;
char c[120];
k=a[0];
c[0]=a[0]/d;
for(int i=1;i<l;i++)
{
k=10*(k-d*c[i-1])+a[i];
c[i]=k/d;
}
return(k%d);
}
int main()
{

char m[120],n[100];
int k,j,p;//value[10][10];
int value[10][10]={{0},{0},{6,2,4,8},{1,3,9,7},{6,4},{0},{0},
{1,7,9,3},{6,8,4,2},{1,9}};

while(scanf("%s%s",m,n) && (m[0]!='0' || n[0]!='0') )
{
l=strlen(m);
p=m[l-1]-'0';//last digit
l=strlen(n);
for(j=0;j<l;j++)
n[j]=n[j]-'0';
if(n[0]==0)
printf("1\n");
else if(p==0 || p==1 || p==5 || p==6)
printf("%d\n",p);
else if(p==2 || p==3 || p==7 || p==8)
{
k=div(n,4);
printf("%d\n",value[p][k]);
}
else
{
k=div(n,2);
printf("%d\n",value[p][k]);
}
}
}

now my problem is
int k,j,p,value[10][10];
value[10][10]={{0},{0},{6,2,4,8},{1,3,9,7},{6,4},{0},{0},{1,7,9 ,3},
{6,8,4,2},{1,9}};
was giving me compiler (gcc) error and when i initialise with
declaration it worked fine as in my program . Plz some one tell me
why is it so .

Jun 18 '07 #1
2 1421
mukesh tiwari wrote On 06/18/07 15:42,:
Hi everybody i want to know about array initialisation .
Today i was solving a problem and here is my code

#include<cstdio>
#include<cstring>
You may find better answers in comp.lang.c++, second
door on the left where that noisy party is in progress
(the party-goers aren't just loaded, they're overloaded).

But *if* you'd like to write C instead, the question
boils down to
now my problem is
int k,j,p,value[10][10];
value[10][10]={{0},{0},{6,2,4,8},{1,3,9,7},{6,4},{0},{0},{1,7,9 ,3},
{6,8,4,2},{1,9}};
was giving me compiler (gcc) error and when i initialise with
declaration it worked fine as in my program . Plz some one tell me
why is it so .
... and this turns out to be Question 8.3 in the
comp.lang.c Frequently Asked Questions (FAQ) list at

http://www.c-faq.com/

--
Er*********@sun.com
Jun 18 '07 #2
mukesh tiwari <mu****************@gmail.comwrites:
Hi everybody i want to know about array initialisation .
Today i was solving a problem and here is my code

#include<cstdio>
#include<cstring>
Those are C++ headers. Either write C or post to comp.lang.c++.

But as it turns out, the rest of your program appears to be valid C
(apart from the error you're asking about).

Incidentally, the way you format your code makes it very difficult to
read. Use consistent indentation. I use 4 columns for each level;
some poeple use up to 8. Avoid tab characters for code posted to
Usenet; try to use just spaces for indentation. (I suspect your own
tab settings are different from mine. I see your code with 8-column
tabstops, which is normal.

[snip]
now my problem is
int k,j,p,value[10][10];
value[10][10]={{0},{0},{6,2,4,8},{1,3,9,7},{6,4},{0},{0},{1,7,9 ,3},
{6,8,4,2},{1,9}};
was giving me compiler (gcc) error and when i initialise with
declaration it worked fine as in my program . Plz some one tell me
why is it so .
Your first line declares the objects k, j, p, and value; it doesn't
initialize them.

Your second line is not an initialization, it's an assignment. In an
assignment, the right hand side has to be an expression; an
initializer can be either an exression or a more complex construct
such as the one yoy're trying to use here.

You need to make the initialization part of the declaration of value:

int k, j, p;
int value[10][10] =
{ {0},
{0},
{6, 2, 4, 8},
{1, 3, 9, 7},
{6, 4},
{0},
{0},
{1, 7, 9, 3},
{6, 8, 4, 2},
{1, 9} };

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Venkat | last post by:
Hi All, I need to copy strings from a single dimensional array to a double dimensional array. Here is my program. #include <stdio.h> #include <stdlib.h>
7
by: ffld | last post by:
Greetings all i am having a horrible time trying to pass a 2 dimensional array of doubles to a function... basically a watered down version of my code looks like: void t1(double a); int...
2
by: Yudan Yi \(OSU\) | last post by:
Hi I define a function, such as void matrix_multi(double **a, double **b, double **c, int n, int m, int q); then when I called this function, I must first declare double **a, double **b, double...
10
by: Robert Palma | last post by:
I'm having trouble figuring out how to pass a pointer to a double array (1 dimensional) to a C function. Declaring array as: double xx; Declaring func. int process( double *input ) Calling...
8
by: per9000 | last post by:
Hi all, I have a two-dimensional array of data, f.x int's. We can imagine that the array is "really large". Now I want the data in it and store this in a one-dimensional array. The obvious...
15
by: sethukr | last post by:
Hi everybody, While running the following program in GCC, i'm very much screwed. main() { char *ptr1; char arr; int i; char *ptr2;
21
by: =?UTF-8?B?TWFydGluIFDDtnBwaW5n?= | last post by:
Hello, I´m using a very large 2-dimensional double matrix (45.000x45.000) in my program. At the initialization of the matrix: double matrix = new double I am getting an out of memory...
6
by: rakhshanda.malik | last post by:
i want to ask from you that how i can dynamically allocate memory to double dimmensional arry ?please reply.
2
by: barker7 | last post by:
I use a simple double array plus a variable to store the row size to represent two dimensional data. I need to quickly copy this data to a two dimensional array: double. Currently I iterate...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.