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

How to call more than 1 pointer in a c function?

2
WELL, I'm pretty new to C, my program needed to have a function that will transpose or multiply matrices.. since a matrix (or array) of m x n, has a transposed matrix of n x m .. i would need to call 2 arrays/pointers into the Transpose function.. 1 with the original values and the other with the n by m size the array/pointer that i will put something from the original .. So how can the function know which function should be this or this ..

for example,where A[i][j] is the orig. function

Expand|Select|Wrap|Line Numbers
  1. for(i=0; i<column; i++)
  2. {
  3.   for(j=0; j<row; j++)
  4. {
  5.  
  6.   B[i][j]=A[j][i];
  7. }
  8. }
Apr 3 '13 #1
7 1426
weaknessforcats
9,208 Expert Mod 8TB
The function argument names are used by the function. Just make sure your arguments are in the same order as the calling values.
Apr 3 '13 #2
aljon
2
So you mean if i write for example Function(A,B,row,col) to call it.. then it would simply mean that the function would know that since A comes first it would be the original function as it is stated inside the function?

Should i allocate a 2d pointer so that i may call the arrays/pointers into the function? The run error says that," assignmeent of read-only location" what's that supposed to mean? thanks a lot.
Apr 3 '13 #3
vijay6
158 100+
Hey aljon, for Transpose of a matrix you can use this code.

Expand|Select|Wrap|Line Numbers
  1. ...
  2.  

Note: 'm not tested this code. If you have any error while executing this code, post the error message here.
Apr 4 '13 #4
weaknessforcats
9,208 Expert Mod 8TB
Most likely your error is an attempt to use a memory location that does not belong to your program. Often this is caused by using an uninitiaized pointer.

I would allocate the two arrays and then call the function with the two pointers plus the rows and columns.

From inside the function it's not obvious that the function should allocate the second array. If it does allocate the second array and return the address to the calling function then it is not obvious to the calling function that the second array needs to be freed.

The general rule is "he who allocates is he who frees".
Apr 4 '13 #5
vijay6
158 100+
Hey weaknessforcats, I don't have 'C' compiler, that's why i posted the code without testing. But 'm sure that code won't give/show errors.
Apr 4 '13 #6
r035198x
13,262 8TB
@Vijay6
You should not be trying to spoonfeed people anyway. Better point them in the right direction by explaining where their problem is.
Apr 4 '13 #7
vijay6
158 100+
Hey @r035198x, i gave the answer because he said "I'm pretty new to C".
Apr 4 '13 #8

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

Similar topics

3
by: zx.zhangxiong | last post by:
Dear all, I'm puzzled about the usage of class member function. Any help would be appreciated. class Account { ...
3
by: news | last post by:
Hi all, hope you can help me. I have recently set up a mysql database of local pubs, with a web form to add new listings (using PHP to generate an INSERT query). I've just been doing a bit of...
43
by: Tony | last post by:
I'm working with GUI messaging and note that MFC encapsulates the message loop inside of a C++ class member function. Is this somehow inherently less robust than calling the message loop functions...
10
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
9
by: java | last post by:
Hey there, I just removed an elderly PHP4-Installation from my Windows-Box and installed PHP 5.2.1. I used the PHP4-Module as local batchfile- interpreter by E:\ersDHCP>php ./extractLog.php ...
7
by: lovecreatesbea... | last post by:
Shoud we declare non-pointer function parameters with const keywords? int main(void){ int f(const int i); int i; f(i); return 0; }
20
by: Bruce. | last post by:
I am trying to call a member function through a pointer to it and can't get the syntax exactly right. This compiles with an error C2064, term does not evaluate to a function taking 1 argument.. ...
9
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
2
by: kasukur | last post by:
Hi i am new to .net. Can someone please advise how to call a SQL function which returns a cursor using c# i have tried to call using OracleCommand.CommandType = CommandType.StoredProcedure ...
1
by: manu1001 | last post by:
I've an old C function that calls a function pointed by a global function pointer. How do I get it to call a member function of a class object determined at run-time. It'll be complied in a C++...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...

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.