Sponsored Content
Top Forums Programming Read redirected file from stdin in C (a.out < file) Post 302492923 by homeboy on Tuesday 1st of February 2011 11:54:29 PM
Old 02-02-2011
Quote:
Originally Posted by semash!
I need to code a program in C to read it from stdin redirection (i.e. root@box~# ./a.out < file), my question is, how can i do that?

I've tried with functions like fscanf(stdin, "%s->%s", var1, var2), but it only reads the first line of the file. How do i pass to the next line in file, and how do i detect the EOF?

Thanks in advance!
are you sure you get an output?
the < already open stdin on file,no need to do more to redirection.However,"-->" is NOT a seperator for scanf,you can achieve your goal by this:
Code:
int main()
{	
	char line[BUFSIZ];
	char *tok;

	while(fgets(line,BUFSIZ,stdin) != NULL){
		for(tok=strtok(line,"-->");tok != NULL;tok=strtok(NULL,"-->")){
			printf("%s\n",tok);
		}
	}
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Saving a redirected file

What command do I use in order to save a file in directory A/B/C to directory A/D/E. (1 Reply)
Discussion started by: JSP
1 Replies

2. Shell Programming and Scripting

tail -f a log file redirected into a new window?

Is this possible? I am attempting to display a new xterm window and tail -f the log file within that new window. I am currently working on a solaris 8 machine if that has any different meaning than the other platforms. As you can see, I am a newbie to this forum and to UNIX. Any help would be... (2 Replies)
Discussion started by: douknownam
2 Replies

3. AIX

search for a file - errors redirected

hi all, i do search for a file in solaris box in the following format find / -name 'file' -print 2>/dev/null i tried the same thing on AIX box; as i am searching from the root the same way i redirected the errors to /dev/null but find is showing strip off errors and when i just continued... (1 Reply)
Discussion started by: matrixmadhan
1 Replies

4. UNIX for Dummies Questions & Answers

Accessing redirected file inside script

hi, Is there a way to access the redirected file inside the script. Here is what the command line looks like: $ shar * > archive_file.arc I know I can't access the name of archive_file.arc with positional parameters like $1, $2.. Is there any way to figure out what file the output of the... (3 Replies)
Discussion started by: milhan
3 Replies

5. UNIX for Dummies Questions & Answers

redirected output not going to file for all cases

I have to confirm that an engine was not able to run. In the output below you see that it indeed got errors, but it didn't send those messages to the output file. When I run the same thing with a different executable it works. So does this mean something in the executable could cause it not to... (7 Replies)
Discussion started by: brdholman
7 Replies

6. Shell Programming and Scripting

no data redirected to a file with top and grep - why?

HI all, I want to capture cpu data in batch mode of "top" command and redirect to a file like this: top -b > cpu.dat it works! But I want to capture only Cpu lines, so i have: top -b | grep ^Cpu >cpu.dat Then I got an empty output file. Why? Could somebody explain and help me to make it... (15 Replies)
Discussion started by: fongthai
15 Replies

7. HP-UX

STDIN Devie File Name and Location

Hi all, I want to know the device filename of STDIN in HPUX. As the same is available on other platforms at /dev/ directory as "/dev/stdin", i can't find any filename for STDIN at /dev/ in HPUX. Please let me know the name and location of device file of STDIN on HPUX. Thanks regards,... (0 Replies)
Discussion started by: erra_krishna
0 Replies

8. UNIX and Linux Applications

missing delimiters when mysql output is redirected to log file

Hi, Pls check that '|' and '+' present in Step-1 are not copied to log file in Step-3. Pls suggest how to get the exact output from Step-1 (i.e. with out losing '|' and '+') in to a log file ~Thanks Step-1: Execute command > mysql -utest -ptest -htesthost testdb -e "select * from... (3 Replies)
Discussion started by: newbielgn
3 Replies

9. Shell Programming and Scripting

Deleting redirected pwd from file.

Hi echo " username " read username echo "password" stty -echo read password stty echo through read i am taking standard input and redirecign them to a file echo " username=${username}/${password} " > file.lst now from the same shell script i want to delete the password (i.e... (4 Replies)
Discussion started by: rosheks
4 Replies

10. Shell Programming and Scripting

awk to use variable instead of stdin or file

on linux systems, i can do something like this: $ JIOO=hello.one.two $ $ awk -F"." '{print $2}' <<< "${JIOO}" however, on older systems or other unix systems that dont have the fancy stuff this does not work. i contemplated using "-v var="${JIOO}" but i dont think that works. any... (7 Replies)
Discussion started by: SkySmart
7 Replies
AU_FREE_TOKEN(3)					   BSD Library Functions Manual 					  AU_FREE_TOKEN(3)

NAME
au_free_token -- deallocate a token_t created by any of the au_to_*() BSM API functions LIBRARY
Basic Security Module Library (libbsm, -lbsm) SYNOPSIS
#include <bsm/libbsm.h> void au_free_token(token_t *tok); DESCRIPTION
The BSM API generally manages deallocation of token_t objects. However, if au_write(3) is passed a bad audit descriptor, the token_t * parameter will be left untouched. In that case, the caller can deallocate the token_t using au_free_token() if desired. The tok argument is a token_t * generated by one of the au_to_*() BSM API calls. For convenience, tok may be NULL, in which case au_free_token() returns immediately. IMPLEMENTATION NOTES
This is, in fact, what audit_write(3) does, in keeping with the existing memory management model of the BSM API. SEE ALSO
audit_write(3), au_write(3), libbsm(3) HISTORY
The OpenBSM implementation was created by McAfee Research, the security division of McAfee Inc., under contract to Apple Computer, Inc., in 2004. It was subsequently adopted by the TrustedBSD Project as the foundation for the OpenBSM distribution. AUTHORS
This software was created by Robert Watson, Wayne Salamon, and Suresh Krishnaswamy for McAfee Research, the security research division of McAfee, Inc., under contract to Apple Computer, Inc. The Basic Security Module (BSM) interface to audit records and audit event stream format were defined by Sun Microsystems. BSD
April 19, 2005 BSD
All times are GMT -4. The time now is 02:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy