hi every one im trying to pass to a function an array with its index: -
//this is my struct
-
typedef struct{
-
char word[20];
-
int anagrams;
-
}Word;
-
-
//this is the prototype of the function:
-
int find_anagrams(char **, char **);
-
//code...
-
if(find_anagrams(word_arr[i].word, word_arr[j].word));
-
//code...
-
//the definition(where there is the problem!!!!)
-
int find_anagrams(char *word1, char *word2)
-
{
-
word_arr[i]. // dont work i can not access my struct!!!
-
}
9 1828
hi every one im trying to pass to a function an array with its index: -
//this is my struct
-
typedef struct{
-
char word[20];
-
int anagrams;
-
}Word;
-
-
//this is the prototype of the function:
-
int find_anagrams(char **, char **);
-
//code...
-
if(find_anagrams(word_arr[i].word, word_arr[j].word));
-
//code...
-
//the definition(where there is the problem!!!!)
-
int find_anagrams(char *word1, char *word2)
-
{
-
word_arr[i]. // dont work i can not access my struct!!!
-
}
Unless word_arr is global, you won't be able to access it through the function. Do you want to pass the struct as an arguement instead of just the char *? -
if(find_anagrams(word_arr[i], word_arr[j])){}
-
Please explain what you are trying to do.
This code:
//this is my struct
typedef struct{
char word[20];
int anagrams;
}Word;
//this is the prototype of the function:
int find_anagrams(char **, char **);
//code...
if(find_anagrams(word_arr[i].word, word_arr[j].word));
//code...
//the definition(where there is the problem!!!!)
int find_anagrams(char *word1, char *word2)
{
word_arr[i]. // dont work i can not access my struct!!!
}
You do not pass a char*. You pass a Word or a Word*: -
int find_anagrams(Word *word1, Word* word2)
-
{
-
//in here you use word1->word to use the array
-
}
-
int find_anagrams(struct nameofyourstruct word[], int size);
The previous notation is much more efficient. I just recommended another approach to do so without using pointer.
int find_anagrams(struct nameofyourstruct word[], int size);
The previous notation is much more efficient. I just recommended another approach to do so without using pointer.
This still uses a pointer.
struct nameofyourstruct word[]
is the same as
struct nameofyourstruct* word
This still uses a pointer.
struct nameofyourstruct word[]
is the same as
struct nameofyourstruct* word
There are some slight diferances,but it can be sayed that they are equal..
Savage
There are some slight diferances,but it can be sayed that they are equal..
What are the differences?
What are the differences?
You don't need to allocate memory for [],but you do need to allocate it for *.
Savage
You don't need to allocate memory for [],but you do need to allocate it for *.
This compiles and no memory was allocated. Of course to use these things tou wiull need to allocate memory. I'm just saying that char arr[] and char* arr1 are equivalent since the name fo the array is the address of element 0. Therefore arr and arr1 are both addresses of char, ot char*
The most you might say is that char[] involves an array but the compiler has no way to check this. All this is, really, is initialization syntax where you have the compiler allocate an array based on the number of enumerated elements.
There are some slight diferances,but it can be sayed that they are equal..
Savage
There are no difference in the value context it is used here (read: as a parameter
to a function) a T[] is the same as a T*
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: nospam |
last post by:
Hello!
I can pass a "pointer to a double" to a function that accepts
double*, like this:
int func(double* var) {
*var=1.0;
...
}
|
by: Brett |
last post by:
I have created a structure with five fields. I then create an array of this
type of structure and place the structure into an array element. Say index
one. I want to assign a value to field3 of...
|
by: Sam |
last post by:
Hi All
I have couple of question regarding property of a class and structures.
**** ---- Here is my class and structure ---- *****
1. Public Structure MyPoint
2. Dim p As Point
3. ...
|
by: Leszek |
last post by:
Hi.
Is it possible in javascript to operate on an array without knowing how mamy
elements it has?
What i want to do is sending an array to a script, and this script should
add all values from...
|
by: Sam |
last post by:
Hello I have a structure called Company.
struct Company
{
char *employee;
char *employee_address;
};
I want to build an array of this structure but the number of employees
will change...
|
by: André |
last post by:
Hi,
I have to pass a lot of variables from vb.net to javascript using client
callback. the problem is that there are single variables, but also arrays
with differents indexes.
I have two...
|
by: redefined.horizons |
last post by:
I would like to have an array declaration where the size of the array
is dependent on a variable. Something like this:
/* Store the desired size of the array in a variable named
"array_size". */...
|
by: frizzle |
last post by:
Hi there,
I have a function to create an array of all files in a certain folder,
so i can display the structure.
The actual function is below the message, as is an example of its
output.
As...
|
by: ctj951 |
last post by:
I have a very specific question about a language issue that I was
hoping to get an answer to. If you allocate a structure that
contains
an array as a local variable inside a function and return...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
| |