07-05-2007
C program Output
The output I got for this pgm is "4 4 4 4".
Can any one help me to understand how I got this output.
Also please suggest me some links to learn about argumnets evaluation in C.
# include <stdio.h>
void func(int a, int b, int c, int d)
{
printf("%d %d %d %d", a, b, c, d);
}
int main()
{
int x = 0;
func(++x, ++x, ++x, ++x);
return 0;
}
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi
I have a C++ program that generates a lot of log information on the console, I need this output (printed using printf function) to go to a file since I will use crontab to schedule the job.
I know I can do this:
myprog > myfile
but I don't know how to enter this in crontab.
I use... (3 Replies)
Discussion started by: GMMike
3 Replies
2. UNIX for Dummies Questions & Answers
Hello
I wander if im doing :
ls -l and its giving me lets say 3 results :
-rw-r--r-- 1 blah other 1789 May 19 2003 foo.c
-rw-r--r-- 1 blah other 1014 May 19 2003 foo.h
-rw-r--r-- 1 blah other 270 May 19 2003 foo1.c
now I would like to use the first... (1 Reply)
Discussion started by: umen
1 Replies
3. Programming
1 #include <fcntl.h>
2
3 main(int argc, char *argv)
4 {
5 char buf;
6 int fd, count = 0;
7
8 if (argc > 1)
9 fd = open(argv, O_RDONLY);
10 else
11 fd = 0; /* Use standard input */
12
13 while (read(fd, buf, 1) > 0) {
14 if (count < 5) write(1, buf, 1);
15 ... (3 Replies)
Discussion started by: bishweshwar
3 Replies
4. Shell Programming and Scripting
When I do
time tar cvf /dev/st0 /mnt/junk >> /root/benchlog, I want it to put the output of the time command into the benchlog file, but it put /mnt/junk. How do I get it to put the output of the tar command? (1 Reply)
Discussion started by: jeriryan87
1 Replies
5. UNIX for Dummies Questions & Answers
I Wrote code that forks into two processes, a parent process, and a child process. The parent process will take the arguments to main() and send them one character at a time to the child process through a pipe (one call to write for each character). The child process will count the characters... (1 Reply)
Discussion started by: hansel13
1 Replies
6. UNIX for Advanced & Expert Users
i use the system command to execute a shell command... ca i collect the out put in the form of a string or something using the same C program? (5 Replies)
Discussion started by: damn_bkb
5 Replies
7. Shell Programming and Scripting
I am running a program which probably calla script within, this script executes in a pop window and control returns back to main program.
Whilw this script is executing i can see a number of messages being displayed but I cannot read them ,too fast.
Is their a way I can redirect those... (3 Replies)
Discussion started by: ruchimca
3 Replies
8. Shell Programming and Scripting
Hello, i have a problem with the output from my bash program.
I made this program
#!/bin/bash
BESTANDEN=$* # Plaatst bestanden in de variabele BESTANDEN
TMPFILE=xmlprog.sh.$$.$RANDOM # basisnaam voor tijdelijke bestanden
# controller of het programma correct is aangeroepen
if
then
... (6 Replies)
Discussion started by: dutchspiders
6 Replies
9. Programming
Hello All,
iam a new memeber today i joined this forum.
hope i will get help. the below program takes input strings and give reverse of input string.
&& mv /home/test1/programs/display /home/test1/programs/old
echo " Please enter the test "
read a
echo "$a" > file
wc -c file > file1
perl... (1 Reply)
Discussion started by: ameyrk
1 Replies
10. Shell Programming and Scripting
hi,
i have posted the same kind of the question in some other forum of the same site. but realized that it is supposed to be here so i am reposting it .this is the perl script written to check for particular pattern.
my file 1 would look like this
hwk:678:9878:asd:09: abc cfgb 12 nmjk ......... (3 Replies)
Discussion started by: anurupa777
3 Replies
LEARN ABOUT SUNOS
closefrom
closefrom(3C) Standard C Library Functions closefrom(3C)
NAME
closefrom, fdwalk - close or iterate over open file descriptors
SYNOPSIS
#include <stdlib.h>
void closefrom(int lowfd);
int fdwalk(int (*func)(void *, int), void *cd);
DESCRIPTION
The closefrom() function calls close(2) on all open file descriptors greater than or equal to lowfd.
The effect of closefrom(lowfd) is the same as the code
#include <sys/resource.h>
struct rlimit rl;
int i;
getrlimit(RLIMIT_NOFILE, &rl);
for (i = lowfd; i < rl.rlim_max; i++)
(void) close(i);
except that close() is called only on file descriptors that are actually open, not on every possible file descriptor greater than or equal
to lowfd, and close() is also called on any open file descriptors greater than or equal to rl.rlim_max (and lowfd), should any exist.
The fdwalk() function first makes a list of all currently open file descriptors. Then for each file descriptor in the list, it calls the
user-defined function, func(cd, fd), passing it the pointer to the callback data, cd, and the value of the file descriptor from the list,
fd. The list is processed in file descriptor value order, lowest numeric value first.
If func() returns a non-zero value, the iteration over the list is terminated and fdwalk() returns the non-zero value returned by func().
Otherwise, fdwalk() returns 0 after having called func() for every file descriptor in the list.
The fdwalk() function can be used for fine-grained control over the closing of file descriptors. For example, the closefrom() function can
be implemented as:
static int
close_func(void *lowfdp, int fd)
{
if (fd >= *(int *)lowfdp)
(void) close(fd);
return(0);
}
void
closefrom(int lowfd)
{
(void) fdwalk(close_func, &lowfd);
}
The fdwalk() function can then be used to count the number of open files in the process.
RETURN VALUES
No return value is defined for closefrom(). If close() fails for any of the open file descriptors, the error is ignored and the file
descriptors whose close() operation failed might remain open on return from closefrom().
The fdwalk() function returns the return value of the last call to the callback function func(), or 0 if func() is never called (no open
files).
ERRORS
No errors are defined. The closefrom() and fdwalk() functions do not set errno but errno can be set by close() or by another function
called by the callback function, func().
FILES
/proc/self/fd directory (list of open files)
USAGE
The act of closing all open file descriptors should be performed only as the first action of a daemon process. Closing file descriptors
that are in use elsewhere in the current process normally leads to disastrous results.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|MT-Level |Unsafe |
+-----------------------------+-----------------------------+
SEE ALSO
close(2), getrlimit(2), proc(4), attributes(5)
SunOS 5.10 27 Apr 2000 closefrom(3C)