LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-15-2012, 02:18 AM   #1
veredv
LQ Newbie
 
Registered: Aug 2012
Posts: 1

Rep: Reputation: Disabled
including a file in linux


Hi,
I need your help, I am trying to initialize array by including a file.
Each(File1.tbl) file have a number in it.
code:

unsigned char sFileParams::array[4] = {
{
#include "File1.tbl"
},
{
#include "File2.tbl"
},
{
#include "File3.tbl"
},
{
#include "File4.tbl"
}
};

The following code works in windows ,but in linux I get the following error:
"braces around scalar initializer for type unsigned char".
Thanks!
 
Old 08-15-2012, 02:32 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
this is not related to linux or windows, but the language you use and the compiler. How did you try them?
 
Old 08-15-2012, 06:40 AM   #3
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Moderator Response

Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 08-15-2012, 06:46 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Then simplify it:

Code:
unsigned char sFileParams::array[4] = {
#include "File1.tbl"
,
#include "File2.tbl"
,
#include "File3.tbl"
,
#include "File4.tbl"
};
 
Old 08-16-2012, 01:25 AM   #5
Jerry Mcguire
Member
 
Registered: Jul 2009
Location: Hong Kong SAR
Distribution: RedHat, Fedora
Posts: 201

Rep: Reputation: 31
is it necessary to specify array[4]? I thought array[] would be sufficient.

Anyway, this is not a good practice of using #include and should not be encouraged.
If the FileX.tbl never get updated, write those numbers in your code. If these files are dynamic, your code should read the numbers in runtime instead.

Last edited by Jerry Mcguire; 08-16-2012 at 01:30 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: redirect stderr to file including name of file with the error SilversleevesX Programming 11 07-27-2010 03:06 PM
how to create a new file including content from reading another file !? silverhand Programming 2 10-06-2007 04:33 PM
including more file system ramesh_manu Red Hat 1 02-06-2007 11:46 AM
Including header file using HTML hoho4rd Programming 4 12-05-2006 11:20 AM
How to make a image file for my disk( Including win2000&Redhat Linux system)? teradyne Linux - Software 3 06-02-2004 04:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration