Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 accessing external variables in C

views
     
TSTereno
post Feb 26 2006, 03:59 AM, updated 20y ago

Tenacious Midfielder
******
Senior Member
1,619 posts

Joined: Jan 2003
From: Land of the Polar Bears!


Hey guys..I have 3 files..When i try to compile my file (bigtime.c) it gives me an error saying undefined reference _pic . I don't know why. I can access PICCOLS and PICROWS no problem..but I cannot access pic itself. Anyone can help me?

header file called pic.h :
CODE
#define PICCOLS 15
#define PICROWS 14

extern char *pic[11][PICROWS];


my file called bigtime.c:
CODE
#include <stdio.h>
#include "pic.h"


int main(int argc, char **argv)
{
 if (argc == 1) {
    fprintf(stderr, "One argument required");
 }
 else if (argc > 2) {
      fprintf(stderr, "Too many arguments given, only one argument allowed");
 }
 else {

    printf("%d\n", PICROWS);
    printf("%d", PICCOLS);
    printf("%s", pic[0][1]);
 }
 return (0);
}


the file i want to access array called pic.c :

CODE
char *pic[11][14] = {
   {
"    ######     ",
"    ######     ",
"  ##      ##   ",
"  ##      ##   ",
"##          ## ",
"##          ## ",
"##          ## ",
"##          ## ",
"##          ## ",
"##          ## ",
"  ##      ##   ",
"  ##      ##   ",
"    ######     ",
"    ######     ",
   },
   {
"      ##       ",
"      ##       ",
"    ####       ",
"    ####       ",
"  ##  ##       ",
"  ##  ##       ",
"      ##       ",
"      ##       ",
"      ##       ",
"      ##       ",
"      ##       ",
"      ##       ",
"  ##########   ",
"  ##########   ",
   },
   {
"  ##########   ",
"  ##########   ",
"##          ## ",
"##          ## ",
"            ## ",
"            ## ",
"  ##########   ",
"  ##########   ",
"##             ",
"##             ",
"##             ",
"##             ",
"############## ",
"############## ",
   },
   {
"  ##########   ",
"  ##########   ",
"##          ## ",
"##          ## ",
"            ## ",
"            ## ",
"  ##########   ",
"  ##########   ",
"            ## ",
"            ## ",
"##          ## ",
"##          ## ",
"  ##########   ",
"  ##########   ",
   },
   {
"##             ",
"##             ",
"##        ##   ",
"##        ##   ",
"##        ##   ",
"##        ##   ",
"##        ##   ",
"##        ##   ",
"############## ",
"############## ",
"          ##   ",
"          ##   ",
"          ##   ",
"          ##   ",
   },
   {
"############## ",
"############## ",
"##             ",
"##             ",
"##             ",
"##             ",
"############   ",
"############   ",
"            ## ",
"            ## ",
"##          ## ",
"##          ## ",
"  ##########   ",
"  ##########   ",
   },
   {
"  ##########   ",
"  ##########   ",
"##          ## ",
"##          ## ",
"##             ",
"##             ",
"############   ",
"############   ",
"##          ## ",
"##          ## ",
"##          ## ",
"##          ## ",
"  ##########   ",
"  ##########   ",
   },
   {
"############## ",
"############## ",
"##        ##   ",
"##        ##   ",
"        ##     ",
"        ##     ",
"      ##       ",
"      ##       ",
"    ##         ",
"    ##         ",
"    ##         ",
"    ##         ",
"    ##         ",
"    ##         ",
   },
   {
"  ##########   ",
"  ##########   ",
"##          ## ",
"##          ## ",
"##          ## ",
"##          ## ",
"  ##########   ",
"  ##########   ",
"##          ## ",
"##          ## ",
"##          ## ",
"##          ## ",
"  ##########   ",
"  ##########   ",
   },
   {
"  ##########   ",
"  ##########   ",
"##          ## ",
"##          ## ",
"##          ## ",
"##          ## ",
"  ############ ",
"  ############ ",
"            ## ",
"            ## ",
"##          ## ",
"##          ## ",
"  ##########   ",
"  ##########   ",
   },
   {
"      ##       ",
"      ##       ",
"    ######     ",
"    ######     ",
"      ##       ",
"      ##       ",
"               ",
"               ",
"      ##       ",
"      ##       ",
"    ######     ",
"    ######     ",
"      ##       ",
"      ##       ",
   },
};




wKkaY
post Feb 26 2006, 08:37 AM

misutā supākoru
Group Icon
VIP
6,008 posts

Joined: Jan 2003
What compiler and development environment are you using?
TSTereno
post Feb 26 2006, 10:14 AM

Tenacious Midfielder
******
Senior Member
1,619 posts

Joined: Jan 2003
From: Land of the Polar Bears!


I was using Dev C++ which probably uses Mingwin, is there anyway to compile pic.c along with bigtime.c together? I am forced to use Cygwin and use gcc to compile.


I have another question:
What is the difference between:
num = argv[1][0] - '0';

and
num = argv[1][0];

I can see the difference but what does "- '0'" do??
wKkaY
post Feb 26 2006, 11:28 AM

misutā supākoru
Group Icon
VIP
6,008 posts

Joined: Jan 2003
To compile a few files at once, just supply them as additional arguments to gcc, e.g.: gcc -o outputfile file1.c file2.c etc.c. A "makefile" is usually written to automate this task (among others).

Those single characters enclosed in quotes are called "character literals". They are its ASCII representatives. E.g. 'A' = 65. You can demonstrate this to yourself by trying: printf("%d %d", 0, '0');
dstl1128
post Feb 27 2006, 06:50 PM

Look at all my stars!!
*******
Senior Member
4,464 posts

Joined: Jan 2003
'0' = integer value of 48 (or 0x30)

if argv[1][0] is:
'0', then argv[1][0] - '0' yields 0 integer value.
'1', then argv[1][0] - '0' yields 1 integer value.

 

Change to:
| Lo-Fi Version
0.0150sec    1.24    5 queries    GZIP Disabled
Time is now: 23rd December 2025 - 01:19 PM