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 1835
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(c har **, char **);
//code...
if(find_anagram s(word_arr[i].word, word_arr[j].word));
//code...
//the definition(wher e there is the problem!!!!)
int find_anagrams(c har *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(s truct nameofyourstruc t word[], int size);
The previous notation is much more efficient. I just recommended another approach to do so without using pointer.
int find_anagrams(s truct nameofyourstruc t 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 nameofyourstruc t word[]
is the same as
struct nameofyourstruc t* word
Savage 1,764
Recognized Expert Top Contributor
This still uses a pointer.
struct nameofyourstruc t word[]
is the same as
struct nameofyourstruc t* 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?
Savage 1,764
Recognized Expert Top Contributor
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.
JosAH 11,448
Recognized Expert MVP
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 the structure inside the array.
When I try this, an error about late assignment appears. Is it possible to
assign a value to a structure field that is in an array?
I'm currently getting around the problem by creating a new structure, assign...
|
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. Dim ptColor As Color
4. End Structure
|
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 that array
Could you show me a little example how to do this?
Thanks.
|
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 thorughout the course the programs use so it will need to
| |
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 questions:
1) is this technology made for passing a lot of variables or in fact only
for one?
2) does it exist a esier way to pass the values and to recover them in
javascript?
|
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". */
unsigned short int array_size = 25;
/*Declare an array named "numbers" using the variable initialized
above. */
unsigned short int numbers;
|
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 one can see, the filesize is also stored in the array (more info
will be added, like filemtime),
what i need is to sum all bytes per folder.
|
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 that
structure, is this valid?
As shown in the code below I am allocating the structure in the
function and then returning the structure. I know if the structure
contained only simple types (int, float) this will work without
problems as you...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |