![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question about NULL Character & fgets() | f.ben.isaac | High Level Programming | 2 | 11-04-2008 12:31 PM |
| Problem with handling SIGINT | JamesGoh | High Level Programming | 3 | 02-24-2008 10:39 PM |
| Problem with fgets and rewind function .. | user_prady | High Level Programming | 1 | 02-08-2008 05:20 AM |
| Cannot catch SIGINT while serial break condition occurs | gzz | High Level Programming | 13 | 11-23-2007 08:06 AM |
| fgets() | skanky | High Level Programming | 4 | 09-11-2002 10:32 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
[C] fgets problem with SIGINT singlal!!!
Hi all,
I have this method to read a string from a STDIN: PHP Code:
PHP Code:
can i "simulate" the ENTER key pressed writing a particular ASCII char into STDIN??? Thanks a lot in advance, Martin |
|
||||
|
Code:
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void readLine(char *inputBuffer)
{
char *p=NULL;
*inputbuffer=0x0;
if(fgets (inputBuffer, MAX_LINE, stdin)==NULL)
{
if(feof(stdin)) return;
if(errno == EINTR)
{
*readLine=0x0; /* or do what you want to a partial read */
return;
}
/* other errors */
perror("Fatal error on stdin");
exit(1);
}
/* fflush(stdin) is NOT a defined operation
if this actually works it is "programming by accident"
*/
fflush(stdin);
/* remove '\n' char from string */
/* if the string entered is greater than MAX_LINE
then you are whacking off valid characters
if(strlen(inputBuffer) != 0)
inputBuffer[strlen(inputBuffer)-1] = '\0';
I am assuming MAX_LINE is defined by you and is not some system value
try this instead:
*/
p=strchr(inputBuffer, '\n');
if(p!=NULL)
*p=0x0;
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|