Computer problems,Computer help
*AX SOFT>>>Programming & Design

Help with c programming not c++?


i have a problem. i am asking the user for three values in the main function. I populate an array of size three, scan in the values as variables and then set those variables equal to an array element(i.e. scan in 3 as a and set array[0] = a)is this right?. If so how do i pass this array to another function so i can use the values for computations and print from that function? i would really appreciate it. thnx

i thought i had it figured out but i seem to be passing the address and not the values of a, b, and c

That sounds right. Can't say for sure, because u didn't post your code. What i can say for sure, is that this is how u pass an array to another function... (for print, computations, etc, etc)


void myfunc(int *sa)
{
printf( " 1st array index: %d \n", sa[0] );
}

int main()
{
int array[3];

array[0] = 27;
myfunc(array); //should print " 1st array index: 27"
}

Welcome...thanx choosing my answer! Report It

An array always gets passed as an address. You are probably dereferencing it incorrectly.

void func(int *a, int size)
{
int i = 0;

for (; i < size; ++i)
{
printf("%d\n", a[i]);
}

}


int main ()
{
int array[3] = {1,2,3};

func(array, sizeof(array) / sizeof(int));

return 0;
}

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • In Excel VBA, how could we make a cell border flash?

    I am not sure it is possible, it is certainly not one of the border linestyles (I just iterated through all possible values) One approach might be to store the clipboard contents, then put them ...

  • What is the RSS for?

    RSS stands for Really Simple Syndication. It is basically an XML feed (or file) that sits on a site out on the internet. Any time you get this file from the URL it usually produces an up to date ...

  • Visual Studio 2005: Visual Basic: Cursor position?

    I think your problem here is you are not referencing the cursor from the current form. The form you are working with has a cursor property. Try this: If Not Me .Cursor.Equals(Cursors.D...

  • HELPP! with this c++ program please("Find & Replace"), have my annual lab test tomm!!?

    I think we need some more information about this problem before we can help you. First, how are you reading in the paragraph of text? Is the user going to enter it, or do you read it from a file...

  • I am lost ...in VB.NET?

    I'm not sure about the version of VB.net because i never bought it but used in my school first of all learn VB which is simialar to basic (or Qbasic) language and different from java the...

  • How to run my newly created program in Visual C++?

    to compile or build: select Build and then Build Solution will compile once it has been built you can run your program from the Debug menu by selecting Start Without Debugging -------- EDIT:...

  • ASP ==>grid views?

    Yes, you can. The DataSource property in .Net 2.0 and up can accept anything with an IEnumerable interface, and it will use your public properties to auto-populate columns. E.g. List<MyBusi...

  • PLEASE HELP me start writing this PROGRAM in JAVA?

    Damn that's a large program. Might I ask what it's for? So, unless you are familiar with event listeners and things that respond to user input using the keyboard, I recommend you plac...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster