how exactly does pclose work in C?


 
Thread Tools Search this Thread
Top Forums Programming how exactly does pclose work in C?
# 8  
Old 03-15-2011
Sorry, could you rephrase that?

Ok
the return of pclose() is supposed to be the exit code of the command given to the given pointer to a file descriptor, so here in the code i put in the very top it returns the variable 'pstat', is this equal to the exit number of the given command?
# 9  
Old 03-15-2011
Code:
pid == -1 ? -1 : pstat

is equivalent to
Code:
if(pid == -1) { return(-1); } 
else { return(pstat); }

# 10  
Old 03-15-2011
sorta unrelated question:
if u have an array that not all elements have been put in, and u do a for loop for it, will it crash if it tries to access one of the elements that doesnt have anything in it? If not, is the value equal to NULL ?
# 11  
Old 03-16-2011
Quote:
Originally Posted by omega666
sorta unrelated question:
if you have an array that not all elements have been put in
Please don't use netspeak. We really discourage it here; and if you know what "you" means, you also know how to spell it!

What do you mean by 'put in'? And what kind of array, anyway?
Quote:
and you do a for loop for it, will it crash if it tries to access one of the elements that doesn't have anything in it?
Depends what it is and what you're doing with it. An array of integers may have unpredictable values if you never put anything in it before you used it, but won't crash in of itself. (Of course, the things you do with unexpected numbers may cause it to crash, but that's neither here nor there.) An array of pointers may be full of garbage pointers aimed at nowhere in particular which will crash if you dereference them. Or, worse, they may be pointers to VALID if unintended memory, which will do bizzare unpredictable things instead of crashing.

But in any of these cases it's not the array that's crashing -- it's what you do with the values you find in it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

Discussion at work, would a router work pluging a cable in wan1 and lan1?

hi all. and sorry for the random question, but this sparkled a raging flame-war at work and i want more points of view situation a router, with linux of some sort, dhcp client requesting for ip in wan1 (as usual with wan ports) dhcp server listening in lan1, and assigning ip (as usual... (9 Replies)
Discussion started by: broli
9 Replies

2. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

3. IP Networking

NIC will not work, but it did work.

I have a client machine that was built and loaded with SCO UNIX 2.1.3, (yes it is old). The machine worked fine on the closed network that I tested on in my shop. I then had to change it to the network that it would be connected to. Below is the host file, router and subnet mask file that I usually... (0 Replies)
Discussion started by: NC user
0 Replies

4. UNIX for Advanced & Expert Users

popen and pclose solved

Hi I am trying to use popen function with wrtie option to give inputs to ftp command. #include "stdio.h" int main(int argv ,char *argc) { int size=0; char *buf; FILE *fp; fp = popen("ftp","w"); while(getline(&buf,&size,stdin) != -1) write(fp,buf);... (0 Replies)
Discussion started by: kumaran_5555
0 Replies

5. Shell Programming and Scripting

ls -d does not work

Hi falks, I need to dispaly a list of only directories . As it written in the manual ,the command to do it is 'ls -d'. When i issue 'ls -d' i'm getting: tornado.orca.ent:DB10g :/home/oracle/Create_Database > ls -d . Is anyone have any idea why id does not display directories ,or maybe... (11 Replies)
Discussion started by: nir_s
11 Replies

6. Linux

Come and work for me! (UK)

********nothing too see here!!!****** (2 Replies)
Discussion started by: TonyChapman
2 Replies

7. Linux

How does it work?

Can anyone explain how Graphic LCD (CSTN / STN) work in Unix... From Graphic file thro driver code to display....? Thanks (1 Reply)
Discussion started by: nat123
1 Replies

8. UNIX for Dummies Questions & Answers

cant get this to work

whoami | grep < $1 | echo $1 trying to write a script that finds out who the user is and then takes occurences of that username from a file that is passed as an argument and then displays it (6 Replies)
Discussion started by: iago
6 Replies

9. UNIX for Advanced & Expert Users

pclose returning -1

Hi all, In my application i am trying to select some text & then give it to print. for this i am opening a stream using popen & then later closing using pclose. Now this is working fine in my environment (solaris) but the pclose function is failing at my clients m/c. Even though print is... (3 Replies)
Discussion started by: nimishm123
3 Replies

10. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies
Login or Register to Ask a Question