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

Re: Store int* array

On Wed, 27 Aug 2008 00:07:35 -0700, MN wrote:
[snip]
>
for (i = 0; i < in2; i++)
{
if (i == 0)
{
//printf("- %d\n", &view_var1[i]);
printf("- %d\n",var1[i]);
}
>
else
{
//printf("%d %d\n", i-1, &view_var1[i]);
printf("%d %d\n", i-1, var1[i]);
}
}
return 0;

}

int* function(int in1, int in2)
{
int i = 0;
if (var1 != NULL)
free(var1);
var1 = (int*)malloc (sizeof(int*)* in2);
for (i = 0; i < in2; i++)
{
if (i == 0)
var1 [i] = 0;
else
{
if (i == 1)
var1[i]= 1;
else
var1[i] = var1[i-1]*2+in1;
}
}
return (var1[in2]);
}
The return type is int* but here you return int. The correct
way would be to write:

return var1+in2;

But then again, that just returns a pointer pointing beyond the
allocated array. I'm guessing you actually want the beginning
of the array:

return var1;

--
OU
Aug 27 '08 #1
1 1531
MN
Thanks for your help.
Aug 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: forums_mp | last post by:
I've got an STL class (see below) with two functions to store and retrieve data - msg structs. The "Store" function when called will copy the received message (depending on which message) into...
3
by: Tony Johansson | last post by:
Hello! Assume you want to store field object that a chess board consist of. A chess board consist of 64 fields where each field is either white or black. Now to my question how should I...
12
by: arkobose | last post by:
my earlier post titled: "How to input strings of any lengths into arrays of type: char *array ?" seems to have created a confusion. therefore i paraphrase my problem below. consider the...
0
by: wASP | last post by:
I thought it was something relatively simple: ViewState = SomeObj; Then: SomeObj = ViewState; So, in my own code, I have this on the initial load:
11
by: mwebel | last post by:
Hi, i had this problem before (posted here and solved it then) now i have the same problem but more complicated and general... basically i want to store the adress of a istream in a char* among...
7
by: rhitz1218 | last post by:
Hi all: Is it possible to store an integer array to another integer array? Or should I use an array of pointers that will point to a particular array? Thanks for the help.
2
by: hikmaz | last post by:
I am trying to get the rightmost digits (%10) of a number (taken from the user) and store it into successive array locations and get rid of the rightmost digit (\10) to store the next and so on and...
3
by: almo | last post by:
hi guys, I have question about writing a function that will store some data from a file in an array, then when that function is call in main, I can use that array in the main() for calculation. Here...
0
by: Jens Thoms Toerring | last post by:
MN <mazouz.nezhate@gmail.comwrote: Why do you declare it as extern if you define it just two lines later?
13
by: tekinalp67 | last post by:
hi, i am trying to implement a B+ tree. There is no specification in the implementation so i am using arrays to implement the B+ tree. However, there is a problem that i encountered which is I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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:
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
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: 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...

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.