User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 374,453 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,782 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 1469 | Replies: 1
Reply
Join Date: Jun 2005
Posts: 8
Reputation: rkarimi is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rkarimi rkarimi is offline Offline
Newbie Poster

Help Initialization of Const Arrays by function

  #1  
Jun 10th, 2005
/*
I'd like to read some data from hard disk & then manipulate them as const variables. Here a simple version is attached. I do not know how to Initialize a const array by FUNCTION */

#include <stdlib.h>
#include <stdio.h>
int *MAKE(const int n,int i)
{
    int V[n];
    V[0]=10*i;
    V[n-1]=2;
    printf("%d",V[0],V[n-1]);
    return V;
}

int main()
{
    const int n=5;
    int i=2;
    int *A_Load=MAKE(n,i);
    printf("%d",A_Load[0],A_Load[n-1]);
    return 1;
}
<< moderator edit: added code tags: [code][/code] >>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,418
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 15
Solved Threads: 137
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Initialization of Const Arrays by function

  #2  
Jun 10th, 2005
Consider malloc/free to create the array. Functions that use the array should take a pointer to const.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 12:43 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC