Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-18-2008, 10:53 PM   #1
LQ Newbie
Registered: Apr 2007
Posts: 4

Rep: Reputation: 0
Question Problem when use getc function before creating a new process with execve()

I am facing a strange problem.
I am using execve() to run a program with new enviornment variables.
before I call execve(), I have to read an input from the user.
When the user types the input, and i read it in my code using gets(); my program works fine, and execve calls other executable as expected.
But if instead of gets() I read user input using getc(), as in
do {
*(pDisp + iCnt++) = getc(stdin);
}while(*(pDisp + (iCnt - 1))!='\n');

then when execve() function is encountered in the code,
It does nothing, it does not call my other executable code.

Any hints ?
Old 02-20-2008, 08:29 PM   #2
Senior Member
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Originally Posted by anuj_sri View Post
Any hints ?
How about a WAG?

My C is a bit rusty, but I believe gets() will terminate its output with a null character. Your loop terminates it with a newline. I am wondering if this input is used to set up the environment variables for the execve() call and the lack of a null character is tripping things up.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in execve function vinayl Linux - Kernel 0 01-26-2008 07:34 AM
Call function in another process Gabbiadini Programming 1 10-27-2007 08:17 AM
C getc without CR astropirhana Programming 5 09-01-2006 04:03 PM
Please teach me how to use getc(stdin) Eileen Programming 12 12-20-2004 12:34 AM
C/SDL; creating my own drawLine function TheLinuxDuck Programming 4 09-20-2002 10:34 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:15 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration