UNIX only:
[code]
getenv("TZ");
[/code]

will return the timezone setting. The result is in the form
xxxNxxx, example MST7MDT. TZ has to be set for localtime() to return the correct time. MST is GMT +7. If TZ is not set the system is running GMT by default. Assuming time has been set.....
NY is EST5EDT. It's GMT+5.

SpS commented: Ah ~~ SunnyPalSingh +3

What normally is done (assuming that only one of the code pieces has a main() ) is to compile each of the sourcefiles into a separate object file and then link them all into one program.

To simplify a compile you can create a makefile to do this, or create a project in IDE's like Visual Studio.

An example using g++
[code]
g++ file1.cpp file2.cpp file3.cpp -o myprogram
[/code]

~s.o.s~ commented: Good help - ~s.o.s~ +8

This is allowable C, but can cause you problems if you are not super careful - meaning: it will cause problems. But it does answer your question.
[code]

include

int myfunc(const char a, const char b, const int i)
{
............. stuff
return 1;
}

void foo(char a, char b, int c)
{
typedef int (*Fx)();
Fx fx[2]={strcmp,myfunc};
int result=0;

if (c==1)
result=fx0;
else
result=fx1;
if(result==0)
printf("okay\n");
}
[/code]

Wow.
[code]
void main() - don't use void main. main() returns an int.
{
clrscr();
while(i--!=6) - where is i set to some intitial value?
i=i+2; - this is the end of the while loop
I think you are missing {} to make a while block?
printf("%d\n",i);
getch();
}

[/code]
You do realize that your while loop subtracts then adds to the same variable, essentially in the same statement. Eeeek...

Back up.

What are you trying to do?

andor commented: andor agrees +4

HPUX supports alloca() -
it has advantages and disadvantages
[code]
good - it automatically frees all objects created by alloca calls when
the function making those calls exits

good - it is about 100X faster than malloc

bad - it allocates from stack, not heap. stack space size limits
are nowhere near a generous
bad - it is REALLY easy to reference a pointer to garbage
or trash the stack of another function
[/code]
Example mediocre code:
[code]

include
include
include <sys/resource.h>
include
include
include
include
define MAX 100000

void foo(void)
{
int i=0;
char *p[MAX]={NULL};
for ( i = 0 ; i < MAX ; i++ )
p[i] = malloc( rand()%456 );
for ( i = MAX ; i>0 ; i-- )free( p[i] );

}
int foo1(void)
{
int i=0;
char *p[MAX]={NULL};
for ( i = 0 ; i < MAX ; i++ )
p[i] = alloca( rand()%456 );
}

void badfoo(void)
{
int i=0;
char *p[MAX]={NULL};
for ( i = 0 ; i < MAX ; i++ )
p[i] = malloc( rand()%456 );
}

void process(struct rusage p, char when)
{
printf("%s\n", when);
printf(" / user time used / %8d %8d\n", p->ru_utime.tv_sec,p->ru_utime.tv_usec );
printf(" / system time used / %8d %8d\n", p->ru_stime.tv_sec,p->ru_stime.tv_usec );
printf(" / integral shared memory size / %8d\n", p->ru_ixrss );
printf(" / integral unshared data / %8d\n", p->ru_idrss );
printf(" / integral unshared stack / %8d\n", p->ru_isrss );

}

int main()
{
int ret=0;
int i=0;
int who= RUSAGE_SELF; ...

[QUOTE=jim mcnamara;251589]I'd use arrays:
[code]

!/bin/ksh

optfile=filename
set -A opts \
$(awk 'BEGIN {FS="="} { if($0~ / page_size/) { prinf("%s ", $2}}' $optfile; echo"")
for i in 0 1 2
do
echo ${opts[i]}
done

[/code]
If you're using bash just "declare" opts as an array.[/QUOTE]
I changed it so awk puts it all on the same line.

I'd use arrays:
[code]

!/bin/ksh

optfile=filename
set -A opts $(awk 'BEGIN {FS="="} { if($0~ / page_size/) { print $2}}' $optfile)
for i in 0 1 2
do
echo ${opts[i]}
done

[/code]
If you're using bash just "declare" opts as an array.

WolfPack commented: Thanks. +3

[code]

!/bin/bash
we want to copy from path1 to path2
step 1 make all the subdirectories

find /path1 -type d | \
while read dir
do
mkdir /path2"${dir#/path1}"
done

step 2 cp the files

find /path1 -type f | \
while read $file
do
cp "$file" /path2"${file#/path1}"
done

[/code]

In that case you have to use cp. mv does not mv over mount points.

[code]
cat /proc/meminfo
[/code]
shows the current state of memory. The format varies somewhat with Linux distributions. My version of Linux has what you want in the 4 th column on the second line. So, you will need to get the awk statement working for you. Then put it in the C code.
You could also just read /proc/meminfo (read only) as a regular file and find the value using C only.
snippet:
[code]

include

void foo(void)
{
char cmd="awk '{ if(NR==2){print $4}}' /proc/meminfo";
FILE
cmdfile=popen(cmd,"r");
char result[256]={0x0};
while(fgets(result,sizeof(result),cmdfile)!=NULL)
{
printf("%s\n",result);
}
pclose(cmdfile);
}

[/code]

Are you talking about using NFA regexp in a DFA environment?
Start with a DFA tool is the simple answer. There really is no code to convert from one to another, because it doesn't make much sense to do so. C and C++ have regexp libraries available for them. Pick one. Windows provides the .NET version.

You do realize that which tool you use dictates which type of regex processing occurs? To get a list of which tools have what regex flavor (including POSIX) try:

J Friedl 'Mastering Regular Expressions' 2nd ed 2004

Then if you want, download source for one of them.

You are not calling strtok correctly.

try something like this:

void foo(char *string1, char *string2)
{
    char *first=strtok(string1,"|");
    char *second=string2(string2,"|");
    while(first!=NULL)
    {
        printf("%s\n",first);
        first=strtok(NULL,"|");
    }
    while(second!=NULL)
    {
        printf("%s\n",second);
        second=strtok(NULL,"|");    
    }
}

Your logic doesn't make any sense to me...

You want to get to the "got it" statement - this does it.
[code]

!bin/ksh

a=5
while [[ $a -gt 5 ]]
do
echo "a=5 and not went to else cdn."

if [[ $a==5 ]]
then
    echo "a=6" 
fi
echo "a=5 and not worked" 

done
echo "got it"

[/code]

Here is a start - you need to read up on shell scripting

[code]

!/bin/ksh
function gen_data
record performance data, place in a file with each node's
information all on one line

gen_data()
{
for i in 54 72 114 122 123 139 73
do
ssh 10.42.1.$i "hostname && uptime"
done | \
awk ' BEGIN {cnt=0}
{ printf("%s, ", $0)
cnt++
if(cnt % 3 == 0) {printf("\n") }
}' > ./perf_data
}

function check_data
check for load averages (fields 6,7,8) which are greater than 7

check_data()
{
awk -F"," '{ if($6 > 7.0 || $7 > 7.0 || $8 > 7.0)
{print $0 }
}' ./perf_data > ./email.dat

do we have any warnings to email ?
if [ -s email.dat ]; then
   cat ./email.dat | \
       usr/bin/mailx -s 'Performance warning' you@someplace.com
fi

}

main control loop
run the two functions every ten minutes 60 seconds * 10 = 600

sleepy_time=600

loop forever .....

while true
do
gen_data
check_data
cat ./perf_data >> ./perf_data.log
sleep $sleepy_time
done
[/code]

evlmcgyver commented: Excellent! Clean, neat, and tidy!! +0

chris - you're correct. Perl is overkill which I guess was my point to start with.
3 lines of awk:
[code]
awk ' BEGIN {connected=-1}
$2 ~ /^connected/ {connected*=-1 ; continue}
connected<0 {print $0 } ' filename
[/code]
on this file:
[code]
PIN connected
USE TEST ;
PORT
LAYER TRUE ;
END
END connected

PIN address
USE TEST ;
PORT
LAYER TRUE ;
END
END address

PIN connected
USE TEST ;
PORT
LAYER TRUE ;
END
END connected
[/code]
produce this output:
[code]
kcsdev:/home/jmcnama> t.awk

PIN address
USE TEST ;
PORT
LAYER TRUE ;
END
END address

[/code]

voidyman commented: brilliant! +1