Hello Everbody,

I have 2 arrays called

``````Array 1                                                       Array 2

Stuid      stuname                                   stuid              Bookname
1            Albie                                       1                   OOPS
2            Morkel                                      2                   CNA
3            Jmes                                        1                   ComputerNw
3                   OOPs
2                   CNA
``````

Code:

``````#include<stdio.h>
main()
{
//  char array1[2][1],array2[5][1];
char array1[100][100]={'ID1','srini','ID2','Albie','ID3','Kaasi'};
char array2[50][100]={'ID1','OOPS','ID2','STS','ID1','STS','ID1','CTC','ID3','MAT','ID2','MAT'};
printf("We're Begining the Comaprison Here !!\n\n");

search(array1[][],array2[][]);
}

void search(char arr1[100][100],char arr2[100][100])
{       int x = sizeof(arr1); int y = sizeof(arr2);
for(int j=0;j<y;j++)
{   int count = 0;
for(int k=0;k<x;k++)
{
if(arr1[j][0] == arr2[k][0])
{
count += 1;
}
printf("StudentID\t : BooksTanken\t");
printf("%c \t\t %d \t\n",arr1[j][0],count);
}

}
}
``````

Here i have to find Which student how many books taken from the Library..
I wrote the Program but i'm unable to execute
Experts pls Help Me to Figure Out the Problem

And Let me Know if i'm doing something wrong in arrays!

Srini

Edited by pyTony: Reformatted your data as code block to be able to read it

3
Contributors
3
Replies
7
Views
6 Years
Discussion Span
Last Post by Sky_Flyer
1. line 9: when calling a function do not include the [] in the parameter list
`search(array1,array2);`

2. line 13: sizeof does not work for pointers and arrays declared as parameters. sizeof(array1) will always be 4 in 32-bit compilers because array1 is a pointer, not an actual array. sizeof only works with arrays in the same function in which the array is declared, main() in your program. The way to do it is to first declare a macro at the beginning of the program with the desired size, then use that throughout the program. For example `#define SIZE 100

Edited by Ancient Dragon

HI Ancient Dragon,

Thanks for the Reply i was able to understand the first one but in the second i couldn't
Let me say clearly, i want to find the each array length so that i could run the For Loop upto the length of the array
that's what i'm looking for .....

These are the Error Reports i'm getting while Running,
5:23: warning: multi-character character constant
In function 'main':
5: warning: overflow in implicit constant conversion
5:29: warning: character constant too long for its type
5: warning: overflow in implicit constant conversion
5:37: warning: multi-character character constant
5: warning: overflow in implicit constant conversion
5:43: warning: character constant too long for its type
5: warning: overflow in implicit constant conversion
5:51: warning: multi-character character constant
5: warning: overflow in implicit constant conversion
5:57: warning: character constant too long for its type
5: warning: overflow in implicit constant conversion
6:23: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
6:29: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
6:36: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
6:42: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
6:48: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
6:54: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
6:60: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
6:66: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
6:72: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
6:78: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
6:84: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
6:90: warning: multi-character character constant
6: warning: overflow in implicit constant conversion
At top level:
12: warning: conflicting types for 'search'
9: note: previous implicit declaration of 'search' was here
In function 'search':
14: error: 'for' loop initial declarations are only allowed in C99 mode
14: note: use option -std=c99 or -std=gnu99 to compile your code
16: error: 'for' loop initial declarations are only allowed in C99 mode

*hey there ,
1.you can not initialize a 2d array like this...!!!!!!!!

``````char array1[100][100]={'ID1','srini','ID2','Albie','ID3','Kaasi'};
> char array2[50][100]={'ID1','OOPS','ID2','STS','ID1','STS','ID1','CTC','ID3','MAT','ID2','MAT'}
``````

You can initialize it as follows:

``````char array1[3][2]={
{'ID1','srini'},
{'ID2','Albie'},
{'ID3','Kaasi'}};

char array2[6][2]={
{'ID1','OOPS'},
{'ID2','STS'},
{'ID1','STS'},
{'ID1','CTC'},
{'ID3','MAT'},
{'ID2','MAT'}};
``````

it will also give you following error
" error C2015: too many characters in constant..."
because each element can hold only one charecter at each position in the charecter type arra*

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.