Programming :: Return And Exit In C

Jun 3, 2011

What are the uses of return 0, return 1 and exit statements in C

View 4 Replies


ADVERTISEMENT

Programming :: Typeset -i Failing And Return Exit Code 1

Nov 18, 2010

I have this command in ksh:

1. typeset -i INTEGER INTEGER=aaa In all platforms except of Linux it is failing and return exit code 1 Why in Linux it is not failing? I must it for my number tests

2. The same for printf command. Only in Linux the bellow command is not failing: printf "%d" aaa

View 7 Replies View Related

General :: Return -1 Of Main But Get Exit Code Is 255? Why? Pls Advise.

Jun 28, 2011

I learn C++ reading the <C++ primer 4th>, question1.2 let me test if return -1 how the compiler handle this exit code.
and in gcc (GCC) 4.1.1 20070105 (Red Hat 4.1.1-52), I get this show:

[youxi600@Arthas C++ Primer]$ cat q1_2.cpp
int main()
{
return -1;
}
[youxi600@Arthas C++ Primer]$ gcc q1_2.cpp -o q1_2
[youxi600@Arthas C++ Primer]$ ./q1_2
[youxi600@Arthas C++ Primer]$ echo $?
255
[youxi600@Arthas C++ Primer]$
anyone can give me an advise? Many thanks!

View 13 Replies View Related

Programming :: Exit In Script Files Cause Konsole Terminal Itself To Exit?

Apr 11, 2010

I noticed that if I have "exit" in a bash script file., e.g. script.sh,that when the word "exit" is reached, and the script file being executed is not in the PATH nvironment, i.e. ". script.sh", the whole konsole shell profile is exited! What gives here? Is there another command compatible to "exit" to prevent this, or will I just have the leave the "." part in the PATH enviroment, which is, to my understanding, is not recommended? I desire for a "goto" function in bash script files

View 11 Replies View Related

Programming :: Why New Threads Exit When Main Thread Exit

May 22, 2010

In linux, creating thread is same as process (clone()), except the virtual address space gets shared with the parent.If a running main process(thread) creates new thread, and if main thread exits, why should the new thread too exit? both are different entities, The same doesn't happen if the child thread exits, the parent thread would be alive.

View 1 Replies View Related

Programming :: Termios Programming - Without Removing Carriage Return / Enter Key

Jun 30, 2010

I trying to write a UART(interfacing of serial devices) to linux machine but after I execute the following code to receive data I need to enter key (carriage return).... but I don't want to remove carriage return/enter key

[Code]....

View 13 Replies View Related

Programming :: Else &amp; Return Values?

Oct 12, 2010

i am having two small issues with a function i have made.sorry if it is a mess, i am still learning bash.the first is calling the nonpersistssh function (second line) and assigning the return value to nonpersistdiag.the function returns 1, but nonpersistdiag seems to only contain 0. i am unsure on how to proceed.the second problem is the nested else clause on line 10. it is a syntactical error. how would i declare it correctly?

Code: function endsession(){
nonpersistdiag=$[nonpersistssh]# a function that returns an exit code
sudo /etc/init.d/ssh stop; sshdiag=$?

[code]....

View 6 Replies View Related

Programming :: Return Value From A Function?

Nov 15, 2010

On this link [URL]4 a return type is defined

Code:
return ((unsigned int)(unsigned long)base & TBASE_DEFERRABLE_FLAG);
What is the above function returning.I am not clear with definition of what is being returned in the above code.

View 7 Replies View Related

Programming :: What Exactly Does Echo $0 Return

Jan 18, 2010

I'm confused about what "echo $0" in a shell actually return. Consider these tests:

Code:
[root@e11apvl151 ~]# # Login shell:
[root@e11apvl151 ~]# echo $0
-bash
[root@e11apvl151 ~]# # Starting a new shell
[root@e11apvl151 ~]# bash
[root@e11apvl151 ~]# echo $0
bash
[root@e11apvl151 ~]# screen
[root@e11apvl151 ~]# echo $0
/bin/bash

Depending on wether the shell is a login shell, a regular shell, or a screen utility, I get different results.

View 8 Replies View Related

Programming :: Tell If Grep Didn't Return Anything?

Mar 15, 2011

I have a file:

979798707
787862348
766428634

I want to see if all the records in the file are present in the contents of the files of a particular directory.

Basically I want to say if grep doesn't return anything, then report.

For example in /tmp dir I have 4 files and flast 2 values (787862348 and 766428634) are present in the files of /tmp dir, but first one (979798707) is not. I want to echo that in a reporting file.

something like:

while read line
do
# if ! grep -rl $line /tmp
echo $line >> are_not_present
done < "myFile"

How do I achieve " if ! grep -rl $line /tmp"? That is, if the line is found by grep, then grep will print the output, but if grep does'nt find it, it will print nothing. How can I check if grep didn't find it (i.e. printed nothing)?

View 2 Replies View Related

Programming :: C - Return To The Beginning Of A File?

Dec 16, 2010

I'm reading a text file with fscanf using a loop until feof(inFile). How can I return to the top of the file? As in I have one loop that scans until the eof and then after it there's another loop and I want to start from the beginning of the file again scanning to the end of it. How do I get back there?

View 3 Replies View Related

Programming :: Echo Hello Command Does Not Return

Jan 11, 2010

I am testing the serial ports on a Single Board Computer(SBC) running Linux kernel 2.6.29. I usually do this by connecting the serial port to another PC serial port, then doing "cat /dev/ttyS0" on PC and "echo hello > /dev/ttyS0" on the SBC. However in the current system, "echo hello > /dev/ttyS0" command does not return at all! Also no characters appear on the destination port. I am running the echo command as root. The system boot messages show that the serial port in indeed /dev/ttyS0.

View 2 Replies View Related

Programming :: Getting Return Value From Program Ran In Background?

Mar 10, 2010

I think my title pretty much explains it. I am writing a script and I want to start a program in the background, and when that program finishes I want to check the return value to make sure there was no error.For example normal I would do something like this:

#!/bin/sh
program
if [ ! $? -eq 0 ]; then
echo "There was an error"
exit 1
fi

Now I want to do something like this:

#!/bin/sh
PRTN=`program1 &`
program2
if [ ! $? -eq 0 ]; then

[code]....

In this case if program2 finishes before program1, I don't think the return value from program1 $PRTN would be valid at the time it is checked.

View 3 Replies View Related

Programming :: Pthread_create Does Not Return The PID ( Process ID)?

Aug 5, 2010

I am using pthread_create system call to create a thread. However pthread_create does not return the PID ( process ID). Is there any quick way to fınd the PID of the created thread.

View 1 Replies View Related

Programming :: Ofstream Return A Boolean In 'if (!ofs)'?

Mar 19, 2011

C++ code:
Code:
#include<fstream.h>

[code]....

View 4 Replies View Related

Programming :: Can't Understand Return Value Of Gawk?

Mar 10, 2010

I write a little script by bash.

#!/bin/bash
a=`gawk '/Iterations /{print $0}' hoge.log | gawk 'BEGIN{FS=" "}{print ($4)}'`
a=`expr 3 '*' $a`

[code]...

View 13 Replies View Related

Programming :: Prevent Echo As Return Value?

Jan 25, 2010

I have always encountered this problem in ubuntu bash shell scripts that echo command in a function will be treated as a return value when used in a function. e.g.

[code]...

The output would simply be xyz. Hence the echo seems to function as a "return" command when used in a function with a return value.

View 4 Replies View Related

Programming :: Does't Create Directory But Return As Value '0'?

Feb 23, 2010

$val = mkdir $directory, 755
print $val;
does't create directory but return as value '0'

[code]....

View 2 Replies View Related

Programming :: Pthreads Return Value Valid Or Not

Jun 14, 2010

I have confusion regarding pthreads return value. All in short, is the is a valid return value ?

[source]
void * myThrRoutine(void *arg)
{
struct myStruct **myst = (struct myStruct**) arg;
cout<<"In thread "<<(*myst)->var<<(*myst)->msg<<endl;
int x = 20;
pthread_exit((void*)x);
}
[/source]

This seems to work fine on pthread_join , but I want to ensure it is not by chance.

View 1 Replies View Related

Programming :: Python: Get The Return Value Of The Last Function?

Jun 13, 2010

But it's been hell finding an answer, or I just don't know what to look for..I have a prompt that asks for a float, and if the user doesn't put in a valid number, then it should die with an error message.

Code:
def die_with_error():
print 'ERROR: You didn't specify a valid number!'

[code]....

View 2 Replies View Related

Programming :: Bash - Propogate Exit Status ?

Jun 10, 2010

I am running a command pretty similar to the one below:

Code:

I need to capture the exit status of that part of the command.

What I am trying to do is set a variable that can be modified within my_job.sh, and used to exit.

However, no matter what I set "status" to in my_job.sh, it exits with "0".

What can I do differently?

View 3 Replies View Related

Programming :: Bash - Using Exit Status For Decisions

Mar 3, 2010

How exactly can I use the exit status of a command in an if statement ?

Something like this:

Code:

View 3 Replies View Related

Programming :: Gracefully Exit A Background Process?

Jun 7, 2011

I am using a program that reads in data from a serial port and then sends that data out over a TCP connection. The problem I'm having is that the only way I know to exit the program is to do a 'kill PID', but doing this means the program doesn't go through the motions of closing the TCP connection properly so I have to wait some random period of time for the port to free itself or else when I try to start it back up it tells me that it can't bind to the specified port.The general structure of the program is as follows

Code:
int main(){
// initialize some stuff

[code]...

View 1 Replies View Related

Programming :: Filer Doesn't Take Exit Command

Jul 6, 2009

I am trying to write a python script which logs into a NetApp filer and fetches some data. I am using the telnetlib library. Filer does not take exit command. So it expects Control-D. How to send that via python script?

View 5 Replies View Related

Programming :: Init.d Script Does Not Return Prompt?

Jul 9, 2010

I have an a script in /etc/rc.d/init.d script that I would like to start and stop my sample application. I have named my script "foo", then I can start running my application my typing $ foo start but this does not return [OK] like other scripts do and does not return to shell prompt. My application is basically like this

int main()
{
do {
printf("Hi
");
sleep(1);
} while (1);
}

What is missing from my application that prevents from returning the shell prompt?

View 3 Replies View Related

Programming :: Pointer As Function Return Doubt?

Jul 15, 2010

I'm getting some information about C language and this session of a C book (follow the above link) is using a bad example for me. When I'm trying this example of function returning a pointer, my compiler is stating a warning that I return a pointer to a local variable. I realized that it is error prone after all this variable may be override before the function has done his execution. And the author is fooling me saying that this example is "perfectly safe". I'm wrong? There is something that I don't got yet? Sorry but this site is preventing me to post the link of book cause I'm a newbie, so a need the hack it. Just strip out the question signs:

{LINK}
?w?w?w
?cs.cf.ac.uk?

[code]....

View 6 Replies View Related

Programming :: Wrapping Around Functions With Different Return Types?

Feb 1, 2010

I have functions which return different data like: int, char*, double...

I also have a list of datatypes (INTEGER, TEXT, REAL...) which can be returned.

I need to map a datatype with function, which purpose is to return it. Therefore, when I determine a datatype, I would like to call the required function without doing switch all the time.

My idea is to have an array of structs like this:

Code:
struct type_func_map
{
int type;
void (*func_wrapper_int)(void); //void (*func_wrapper_text)(void); void (*func_wrapper_real)(void);
};

[Code].....

View 10 Replies View Related

Programming :: BASH Read File Once Then Return To Top?

Aug 8, 2010

I have a script that reads part of a line, delimited between the first and second intended part by a colon. Then it "chops" the part after the colon, which are words offset by commas (counting them beforehand so as to catch every word in the string's second part), like this:

Code:

"COLORS.JPG:red,orange,yellow,green,"
(Returning)
red

[code]....

single script that parses/breaks both parts of a line like this "COLORS.JPG:red,orange,yellow,green;blue,indigo,violet," so that the two parts, separated into single words (or two and three words, sometimes with spaces) can be used as single-line annotations and written to JPEG files using Exiv2. So far, I haven't been able to come up with a script that does this without one part of the total string(usually that part after the colon) becoming the first word in the second array. In other words, I look for this:

KEYWORDS:

[ ]red
[ ]orange
[ ]yellow

[code]....

Or vice-versa (ie, the second array winds up as a single-line "member" of the first). I think it's because I'm using a single while read loop to read the text file in which the filenames and substrings happen to be. If there's some way of reading a file once and going back to the beginning to read it again in another while loop, I haven't found it.

View 14 Replies View Related

Programming :: C Bool Return Values Conventions

Oct 30, 2010

I have a function that returns a boolean value, True of False. Is there any convention whether 0 = False or 0 = True? It should be obvious, 0=False, 1=True. However programs usually return 0 on success and reserve higher numbers for error values. I.e. if the program finishes successfully (function int main() finishes successfully ), it returns 0 - and that contradicts that 0 should be false.

And especially if I want a function to do some computations on parameters passed by reference and return success status. Should it return 1 (true) for success, or should it return 0 for success - like any Unix program does?

Is there any convention for this?

View 1 Replies View Related

Programming :: Detect Keypress Without Needing Return?

Oct 21, 2010

I'm witting a piece of code that needs to read key presses. However I cannot use them as stream, but rather need discrete reads. The code is to simulate an io board interface. So When I press say "d" I need to read it in instantly, not wait for return. I've tried sdl, but no luck (I'm reading in a thread and it causes some problems) I'm using linux so can't use conio.h functions, I've tired gatch from cureses but this still waits for return.So in C/c++ is there a way I can read instant key presses.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved