473,388 Members | 1,326 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,388 software developers and data experts.

[C] Is this proper way of passing an array to be manipulated

I have limited experience with C and some experience with C++. I am developing code to be used on a microcontroller (which is why I am using the keyword "unsigned") and I want to make sure I am doing this correctly. I want to fill an unfilled array in main using a subroutine, is this the proper way of passing a variable in this situation?

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. void fillZero(unsigned int *data[], unsigned int size);  //Function Prototype
  4.  
  5. int main(void) {
  6.  
  7.     unsigned int myData[2];
  8.  
  9.     fillZero(myData[], 2);
  10.  
  11.     // Additional code that uses the now filled array
  12.  
  13.     return(0);
  14.  
  15. }
  16.  
  17. void fillZero(unsigned int *data[], unsigned int size) {
  18.  
  19.     for (int i=0; i < size; i++) {
  20.  
  21.         data[i] = 0;
  22.  
  23.     }
  24.  
  25. }
  26.  
Thank you for the help.

Jake
Jul 26 '10 #1
1 1369
Banfa
9,065 Expert Mod 8TB
Did it compile?

Any reason you can't just use memset from the C standard library?

Expand|Select|Wrap|Line Numbers
  1. void fillZero(unsigned int *data[], unsigned int size);  //Function Prototype
No this isn't right, [] used in a function prototype is equivalent to declaring a pointer so your type data has type unsigned int **, not what you mean I suspect.

Either us the * or use the [].

Loose the [] from line 9 where you call your function.
Jul 26 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Raju V.K | last post by:
I am developing a web site which requires a set og unique values be transferred between pages and server many times. There fore i decided to put the values in an array so that only one reference to...
5
by: Oeleboele | last post by:
OK, I can't understand this exactly: I have this function: int howdy(void *) I first past this to the function &aCharArray I realized later that this should be aCharArray but... the former...
6
by: DeepaK K C | last post by:
Could anybody tell me how to pass array to a function by value? -Deepak
2
by: Manish | last post by:
Hi, I m facing a problem in re-writing a code from VB to C #. We are using a third party DLL to develop a application of Fax. The current application is already written in VB and we have to...
1
by: Dominic | last post by:
If I have a method private void Set(ref uint x) { x = 3; } how do I use this with an array element? uint a = new uint;
2
by: Neil Munro | last post by:
I'm having some "type" difficulty in passing a .NET array (byref) to a COM based API (Autodesk Inventor). In VB6 the code to return an array of tolerance values is: Dim ToleranceCount As Long...
3
by: jrogers.sw | last post by:
I am using an objectdatasource with a .Net 2.0 ASP page. The SQL for the tableadapter needs to use the IN operator as in WHERE job_id in (111, 222, 333, 444, 555) Job_id is a DBType Decimal and...
1
by: tlinzy | last post by:
I'm converting a VB6 program that passes data (including arrays) to an Excel spreadsheet. I'm having trouble in c# passing the array. I'm getting a type mismatch error. Any ideas? -- Thank You
3
by: shobu | last post by:
passing array checkbox value and update the database <?include 'dbconnect.php'; error_reporting(0);$update_qr="update...
2
by: jonpb | last post by:
Using .NET 3.5, I need to pass an array of structs as parameter to a C++ unmanaged function. The C++ dll stores some data in an unmanaged cache, the function writes the values into the array of...
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.