All of the UNIX OS is written and maintained in C - well some asm. GLIBC, all of the the Linux stuff as well.
What was your sample size when you came to this conclusion?
All of the UNIX OS is written and maintained in C - well some asm. GLIBC, all of the the Linux stuff as well.
What was your sample size when you came to this conclusion?
You can pass the value to another function - and name the variable something else. But you are not gaining anything by doing that.
void refoo(int newname)
{
printf("variable newname=%d\n", newname);
}
void foo(void)
{
int oldname=13;
printf(" variable oldname=%d\n", oldname);
refoo(oldname);
}
As long the variable is in scope the name does not/ cannot change. oldname has function scope in the example above.
I have no idea why the original coder wrote that stuff, except it appears the s/he did not know about the standard C library date/time functions.
date arithmetic is best done with that library - convert a date/time to a struct tm, convert the struct tm to epoch seconds. Do the same thing with another time or date. Now you can add subtract or whatever - like what date & time was it 48 days ago? You don't have to worry about leap years, for example.
Work backwards to get a new date.
The functions you need are
gmtime or localtime
mktime
strftime
You also have to learn what goes into struct tm, so you can build one if your system does not have strptime.
here is some help:
http://publications.gbdirect.co.uk/c_book/chapter9/date_and_time.html
hey thanks for ur help but can u please elaborate on this...what should i add to my code so that it works the way i want it to work?
It sounds like you are coding UNIX. From the man page for system:
If the return value of system() is not -1, its value can be decoded
through the use of the macros described in <sys/wait.h>. For
convenience, these macros are also provided in <stdlib.h>.
Generally, that would be WEXITSTATUS(system("./myscript") );
Try: man 2 wait or info wait.
date -u causes UTC date/time to be displayed - FYI.
If you format date like this:
today=$(date +%Y%m%d)
you get a value like 20080111, this is a number - an integer.
When you split the input reformat it:
newdate="$cyear$cmonth$cday"
then compare integers:
if [[ $today -ne $newdate ]]
then
echo "bad date"
fi
DOS network programming is not directly supported by TURBO C. If someone assigned this task to you then that person must have some linkable files to supply TCP/IP support.
This stuff is VERY old. TURBO C should be banned from classrooms. IMO.
There were some network support libraries here:
http://alumnus.caltech.edu/~dank/trumpet/
What narue meant - flags were set so the compiler put symbol names in the image file. When flags are set NOT to output symbols, then you get assembler.
What code have you written so far?
Short answer would be to have a while loop controlled by the totalinsert and money variables
while( totalinsert < money)
{
/* ask for money here, add it to total insert */
}
/* you get here when you have enough totalinsert */
for i in $(cut -f 1,3 -d: /etc/passwd)
do
echo "${i#*:}" "${i%:*}"
done
This lets you see what is going on.
${i#*:}
is parameter substitution- returns the value just before the colon - a number that is the user id.
${i%:*}
returns the username, so:
arr[number] = name
${i%:*}
was changed from
${i%: *}
which doesn't work, by the way.
Try man (or info) for bash or ksh. This is called parameter substitution using a POSIX shell. It finds substrings.
Do you mean 'will the compiler complain' - no.
'Is it a good idea' - Again, probably not.
Reentrant functions should have all of their data passed to them as arguments, and not use global data structures. Semaphores are traffic cops for access to global objects or shared objects.
This sounds like a threads design problem. What are you trying to do?
Consider calling stat() to get the filesize first. Open the file, then move the file pointer forward to some arbitrary place.
If you assume no last line is ever longer than say, 200 characters,
then fseek() to within 200 character size units of the end of the file.
fread in the last bit of the file into a buffer.
Now you can apply what Narue indicated - you have a container that you can "backwards read" from to get the last line of the file. If you need the last 10 lines, then adjust the file pointer positioning scheme.
If you want to see a generalized algorithm for this, consult the coreutils source for the "tail" utility at
www.gnu.org
try:
#!/bin/ksh
export infile=filename
filedate()
{
perl -e '
use Time::Local;
$mytime = timelocal(0,$ARGV[4],$ARGV[3],$ARGV[1],
$ARGV[0] - 1,$ARGV[2] - 1900);
print "$mytime\n";
' $1 $2 $3 $4 $5
}
compare()
{
keep="None found"
maxallowed=$1
minallowed=$2
result=$minallowed
while read record
do
echo "$record" | tr -s '/' ' ' | tr -s ':' ' '| \
read mon day yr hr mins dummy
filedate $mon $day $yr $hr $mins | read value
if [[ $value -lt $minallowed || $value -gt $maxallowed ]] ; then
continue
fi
if [[ $value -gt $result ]] ; then
result=$value
keep=$record
fi
done < $infile
print "$keep"
}
# Q1
filedate 12 31 2005 23 59 | read min
let min=$min+61
filedate 03 30 2006 23 59 | read limit
compare $limit $min
#q2
let min=$limit+61
filedate 06 30 2006 23 59 | read limit
compare $limit $min
#q3
let min=$limit+61
filedate 09 30 2006 23 59 | read limit
compare $limit $min
#q4
let min=$limit+61
filedate 12 31 2006 23 59 | read limit
compare $limit $min
input file:
10/20/2006 21:24 INFINITY 146144 64213523 N Full Backup
10/13/2006 21:46 INFINITY 144120 60868157 N Full Backup
10/06/2006 21:22 INFINITY 148940 59931237 N Full Backup
09/23/2006 02:14 INFINITY 114239 57878059 N Full Backup
09/15/2006 21:31 INFINITY 137821 58463789 N Full Backup
09/01/2006 23:47 INFINITY 130842 57890925 N Full Backup
08/25/2006 21:34 INFINITY 120475 57706942 N Full Backup
08/11/2006 22:49 INFINITY 105830 54603266 N Full Backup
06/28/2006 23:37 INFINITY 110950 45103754 N Full Backup
output:
kcsdev:/home/jmcnama> closest.sh
None found
06/28/2006 23:37 INFINITY 110950 45103754 N Full Backup
09/23/2006 02:14 INFINITY 114239 57878059 N Full Backup
10/20/2006 21:24 INFINITY 146144 64213523 N Full Backup
C version: returns pi/4
#include <stdlib.h>
double pi_over_4(int n)
{
double iter=3;
int eveodd=1;
double pi=0.;
for(pi=1.; n>0; n--, iter+=2., eveodd=!eveodd)
{
if(eveodd)
pi-=1./iter;
else
pi+=1./iter;
}
return pi;
}
Code caving creates a supplanting vector to user-controlled data sets, and is usually a game hacking technique, it's also used in exploits.
Therefore, it's usually an asm code block.
More than that is totally game-specific and platform-specific information that you'd only get at gaming cheat sites that had forums dedicated to a specific game/platform.
I'd search for the game of interest and platform and the word 'hack' or 'cheat'.
If it not a game thing read:
Shellcoder's Handbook by Jack Koziol
considered to be basic source for what you're discussing. ie. commandeering a process's data set to control it.
You did not explain your full data design. So the answer as to why 5 million hash tables =
one hash for one array.
Explain how you need to lookup values in each array. It would help. It might be possible to hash across all arrays.
BUT.
Your collision rate will be out of this world because you must have zillions of duplicates.
Either duplicate element # in the array or duplicate values in the array. This assumes you do not need to lookup based on the entire array's contents. In that second case, hashing might actually help somewhat.
You will need 5 million different hash tables.
Which meanns that if you are lokking for a given value, say -4, across all of your arrays you will have to consult each hash to see if -4 is in the array and which element it is.
This will result in some performance gain.
I'm assuming that the position of the element and the value in the in the array both have meaning.
It sounds like the data design needs to be rethought -- more than that a hash table will fix your problems. For example, a database can do
highly optimized lookups, like count the number of element #3 that equals 20.
I dunno, don't know enough to about your problem to help, really.
Narue has a site
www.eternallyconfuzzled.com
that has a good explanation of hashing algorithms.
UNIX systems usually come with hcreate, hsearch as an implementation of using Knuth's
original hashing work.
I personally think you've got a data design problem. Possibly you should have put in associative arrays upfront as part of the design.
Hashing added after the fact may only help a little. Depending on how far down the call tree your lookups are embedded in your code.
You have to use either ksh (zsh) or bash to do this - ie., a modern shell with pattern matching.
cd /path/to/files
find . -name '*.err' |\
while read file
do
tmp=${file%%.das*}
mv $file "$file".das
done
Test it somewhere first!
I should have read this earlier.
The answer is no. Unless you are using the Realtime Signal Extension - ie., "realtime signals".
The real question is "Why are you doing this?"
It's not like there aren't USR signals or realtime signals (lots of them) you can't use. No offense, but you're just creating problems for yourself.
try:
#
find $1 -type f -exec grep -l -e '/*' -e '//' {} \; |
while read file
do
grep -q ';' $file
if [[ $? -ne 0 ]] ; then
echo $file | grep -q -e '\.c$' -e '\.h$'
if [[ $? -ne 0 ]] ; then
mv $file "$file".c
fi
fi
done
sed 'n;s/$/;/' filename > newfilename
You need to use sed, and you have to learn about regular expressions.
based on your data a very specific (not generalized) solution is:
$> echo "Here's some text and ~this bit gets removed~, where tilda is the delimiter." |read var
$> echo $var
Here's some text and ~this bit gets removed~, where tilda is the delimiter.
$> echo $var | sed 's/~[A-Za-z ]*.~//1'
Here's some text and , where tilda is the delimiter.
This will generate a report like you asked for.
nawk '
{ shortcode[$11]=$11
causecode[$12]=$12
result[$11 $12]++
}
END{ for( short in shortcode)
{
for(cause in causecode)
{
if(result[short cause])
{
print short, "count", cause, result[short cause]
}
}
}
} ' filename
You will have to write another small script that runs under cron (once every hour) and calls the above nawk code with the correct file name.
awk on Solaris is crippled, you have to use nawk to get the features above.
I don't know sms, so someone else will have to help.
I guess I should add:
stdc allows the use of memcpy with the arguments you stated. What the compiler calls as its own version of run-time memcpy can have any number of aguments. A lot of the API is a simplified wrapper to a much more messy-to-use system call.
It's telling you that you're referencing NULL pointers.
It looks like you're trying to automate vi.
There are such things as "ed scripts" - scripts that invoke the ed editor.
You can use that scripting language easily. vi presents problems because it expects the terminal to be a tty, ed doesn't. Your stdin is a shell script.
man ed
rsh means remote shell. We use this method to access our remote systems. you applied two loops in the solution. But I've said ASM1.log file is on VS01a but not on VS01b, and ASM2.log is on VS01b not on VS01a. so it will give error when executed.
Why loop? you only need two rsh lines. You gain nothing by looping.
script:
# $1 = path to examine
# usage
# myscript /path
find "$1" -type d -print |\
while read file
do
permissions=$(ls -l $file | awk '{print $1}')
echo "$permissions $file"
done
for i in vs01a vs01b
do
for k in 1 2
do
rsh $i echo $(tail -20 /opt/oracle/admin/+ASM/bdump/alert_+ASM"$k".log) >> VS_logs.txt
done
done
For "rsh" do you mean rexec or remsh? Or does rsh create a remote shell on remote systems using your OS?
But yiu have to put the integer values out ther in the file in such a way that you can guarantee a read, ie, put it on a separate line with demarcation so you can see it is not part of the list (in case you forgot to write it in the first place, for example):
!5
1
2
3
4
5
I just picked an "!" at random. If humans are going to read the file as well, try something like "linecount:5" so it doesn't confuse readers.
linux is unix.
It doesn't work in cygwin, however - a linux emulation that runs under windows and calls the Windows API for time stuff.
If for some reason TZ is not set for your login process then
#include <stdio.h>
#include <string.h
char *mytz(char *dest)
{
char result[32]={0x0};
FILE *cmd=popen("cat /etc/timezone","r");
if( cmd!=NULL)
{
fgets(result,sizeof(result),cmd);
pclose(cmd);
strcpy(dest,result);
return dest;
}
return NULL;
}
In linux /etc/timezone will show up something like "US/Mountain" rather
than the MDT thing most other unixes have.
Normally your login .bashrc or .profile (preferably /etc/profile) will have a statement like:
export TZ=`cat /etc/timezone`
su or sudo
Read the man page for su.
Both of these require superuser (root) access.
UNIX only:
getenv("TZ");
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.
The short answer is "yes". If you give an example of the data then we can help you.
The way disk i/o in unix works is that data is parked in an in-memory cache in the kernel - it is not guaranteed to be written to disk when the write() system call is invoked. Every 30 seconds or so the syncer daemon issues a sync command. This forces the kernel to write everything in the kernel buffer to disk.
What you are seeing is an incompleted write operation - for whatever reason. Common reasons are - a signal was sent to the process that terminated it, write() or sync failed because something else filled up the
disk (maybe a temp file) and then that file went away, disk errors caused a fatal error. If it's an nsf mounted disk then the network also becomes an issue. What errors do you see in the log?
Record truncation? Not normal behavior unless the record has embedded ascii nul characters. Lack of disk space or exceeding enabled quotas will also cause the output file to truncate.
grep has a line length limit of 2048 characters.
There also is a concept of largefiles, files which are so big a signed 32 bit file pointer cannot access them > 2.4GB.
Which of these things applies to your case?
file_name=`echo "$file_name" | sed 's/ //g'`
That removes any spaces in the file_name variable
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++
g++ file1.cpp file2.cpp file3.cpp -o myprogram
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.
#include <string.h>
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=fx[0](a,b);
else
result=fx[1](a,b,c);
if(result==0)
printf("okay\n");
}
find does date comparisons for you.
Example - this code deletes files older than 48 hours (2 days):
find /home/julie/trash -type f -mtime +2 -exec rm -f {} \;
myvar="Hi there"
backwards=`echo "$myvar" | rev`
echo "$backwards"
This isn't as straightforward as you might think.
Those perl regexes that look like this
(A)|(B)|(C)
for your "A","B","C" test search will work pretty much.
What OS are you on? Do you have a regex library installed? which one?(if you can tell)...
One way
grep '^TDR ' Inputfile.log
awk is what you want.
Assume your extract code runs like this: extract
and it prints data to stdout.
And assume you have columns of data and you want column #3 to be larger than 10.
extract | awk ' if($3 > 10) {print $0} ' > resultfile
You should read up on awk. One of it's main jobs is filtering data.
Wow.
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();
}
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?
If you don't want the user to notice the script running:
nohup script.sh <parameters> 2>&1 > ./logfile &
As long as your script does not ask for user input this will work. Otherwise you will have to resort to nohup and an expect script or nohup and a here document.
while read text
do
echo "$text" | sed 's#[|:;>]# #g' | read nm1 nm2 nm3 nm4
echo "$nm1 $nm2 $nm3 $nm4"
done < inputfile
echo 'ftp://user:pass@host/path' | sed 's#[|:;>@/]# #g' | read dummy usr pwd hst pth
# or
echo 'ftp://user:pass@host/path' | tr -s '/' ' ' | tr -s ':' ' ' | tr -s '@' ' ' | read dummy usr pwd hst pth
echo $pth
echo $pwd
echo $hst
echo $usr
Andor and AD are correct. What exactly are you trying to do?
If you can give us an exact requirment, we can tell you what to do.