Thread: accessing a variable from another C file

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    29

    accessing a variable from another C file

    Hi,

    I'm trying to assign an array stored in another C file to a pointer in my C program.

    I keep getting the array is undefined

    What is the best way of doing this?
    Disk space: the final frontier

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    29
    Perhaps my example should help:

    In one C file:

    Code:
     const float w[128] = {....}
    Another C file:

    Code:
     float *pointer = (float *)w[0];
    What am I doing wrong?
    Disk space: the final frontier

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    In the c file where you want to access the array in another file
    Code:
    extern const float w[128]
    It is best to place this in a header file included by both files though.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    29
    Thanks. I thought that originally, but I wanted to avoid the use of a header file. Anyway it seems to work with the header approach. Just need to create a pointer variable to it now.
    Disk space: the final frontier

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM