Sponsored Content
Full Discussion: fgets problems newline
Top Forums Programming fgets problems newline Post 302470091 by JohnGraham on Tuesday 9th of November 2010 06:53:58 AM
Old 11-09-2010
Quote:
Code:
if( !searchFileLines( argv[0], "NxNSignOff_ChangeStatusComment" ) )

You're using argv[0], which is the name of the executable. For example, if someone at the command typed:

Code:
./somedir/someprog --with option

Then argc would be 3, and the following is what the argv array would look like:

Code:
argv[0] = "./somedir/someprog"
argv[1] = "--with"
argv[2] = "option"

So you need to use argv[1], or you'll be reading an ELF binary, which will largely be non-printable text.
 

10 More Discussions You Might Find Interesting

1. Programming

fgets()

does anyone knows how to accept a command from a user.. i was wondering to use fgets(), but got no idea how to start it... (4 Replies)
Discussion started by: skanky
4 Replies

2. Programming

Problem with fgets and rewind function ..

Hello Friends, I got stuck with fgets () & rewind() function .. Please need help.. Actually I am doing a like, The function should read lines from a txt file until the function is called.. If the data from the txt file ends then it goes to the top and then again when the function is called... (1 Reply)
Discussion started by: user_prady
1 Replies

3. Forum Support Area for Unregistered Users & Account Problems

newline

I have an old file originally created in vi but read and saved by a word processor at some point. I have ^Ms and know how to substitute them for anything I wish but I still only have one long line when viewed in vi. So I suppose I need to substitute a newline for each ^M but I don't know the... (2 Replies)
Discussion started by: Gale Gorman
2 Replies

4. Programming

Question about NULL Character & fgets()

Assume client send the message " Hello ", i get output such as Sent mesg: hello Bytes Sent to Client: 6 bytes_received = recv(clientSockD, data, MAX_DATA, 0); if(bytes_received) { send(clientSockD, data, bytes_received, 0); data = '\0';... (2 Replies)
Discussion started by: f.ben.isaac
2 Replies

5. Programming

[C] fgets problem with SIGINT singlal!!!

Hi all, I have this method to read a string from a STDIN: void readLine(char* inputBuffer){ fgets (inputBuffer, MAX_LINE, stdin); fflush(stdin); /* remove '\n' char from string */ if(strlen(inputBuffer) != 0) inputBuffer = '\0'; } All work fine but if i... (1 Reply)
Discussion started by: hurricane86
1 Replies

6. UNIX for Dummies Questions & Answers

I'm having problems with a simple for loop on a newline

for i in `seq 1 10 ` ; do printf $i '\n'; done gives me this: 1234567891064mbarch ~ $ (output followed by bash prompt) :( I've tried so many ways to create a newline at the end. Does anyone have any ideas.. Thanks in advance. Sorry (7 Replies)
Discussion started by: 64mb
7 Replies

7. Programming

fgets problems

I've been having trouble with reading past the end-of-file in C. Can anyone find my stupid mistake? This is the minimal code needed to cause the error for me: FILE *f = fopen(name, "r"); if (!f) return; pari_sp ltop = avma; char line; while(fgets(line, 1100, f) != NULL) printf(".");... (23 Replies)
Discussion started by: CRGreathouse
23 Replies

8. Programming

fgets read file line with "\n" inside

Hi, I have a string like this, char str ="This, a sample string.\\nThis is the second line, \\n \\n, we will have one blank line"; if I want to use strtok() to seperate the string, which token should I use? I tried "\n", "\\n", either not working. peter (1 Reply)
Discussion started by: laopi
1 Replies

9. Shell Programming and Scripting

echo without newline

I am trying to make a download progress meter with bash and I need to echo a percentage without making a newline and without concatenating to the last output line. The output should replace the last output line in the terminal. This is something you see when wget or curl downloads files.... (6 Replies)
Discussion started by: locoroco
6 Replies

10. Shell Programming and Scripting

Newline in the file

I have requirement to remove the /n ( newline ) characters from the file. When I open file in VI .. I want to see newline char how to display newline char .. or where can I see the content with newline char visible? (3 Replies)
Discussion started by: freakabhi
3 Replies
getopt(3)						     Library Functions Manual							 getopt(3)

Name
       getopt - get option letter from argument vector

Syntax
       #include <stdio.h>
       int getopt (argc, argv, optstring)
       int argc;
       char **argv;
       char *optstring;

       extern char *optarg;
       extern int optind, opterr;

Description
       The  subroutine	returns the next option letter in argv that matches a letter in optstring.  The optstring is a string of recognized option
       letters; if a letter is followed by a colon, the option is expected to have an argument that may or may not be separated from it  by  white
       space.  The optarg is set to point to the start of the option argument on return from

       The  function places in optind the argv index of the next argument to be processed.  The external variable optind is automatically initial-
       ized to 1 before the first call to

       When all options have been processed (that is, up to the first non-option argument), returns EOF.  The special option --  may  be  used	to
       delimit the end of the options; EOF will be returned, and -- will be skipped.

Diagnostics
       The function prints an error message on stderr and returns a question mark (?)  when it encounters an option letter that is not included in
       optstring.  Setting opterr to 0 disables this error message.

Examples
       The following code fragment shows how one might process the arguments for a command that can take the mutually exclusive options a  and	b,
       and the options f and o, both of which require arguments:
       #include <stdio.h>
       main (argc, argv)
       int argc;
       char **argv;
       {
	      int c;
	      extern int optind, opterr;
	      extern char *optarg;
	      .
	      .
	      .
	      .
	      while ((c = getopt (argc, argv, "abf:o:")) != EOF)
		       switch (c) {
		       case 'a':
			       if (bflg)
				       errflg++;
			       else
				       aflg++;
			       break;
		       case 'b':
			       if (aflg)
				       errflg++;
			       else
				       bproc( );
			       break;
		       case 'f':
			       ifile = optarg;
			       break;
		       case 'o':
			       ofile = optarg;
			       bufsiza = 512;
			       break;
		       case '?':
			       errflg++;
		       }
	       if (errflg) {
		       fprintf (stderr, "usage: . . . ");
		       exit (2);
	       }
	       for ( ; optind < argc; optind++) {
		      if (access (argv[optind], 4)) {
	       .
	       .
	       .
       }

See Also
       getopt(1)

																	 getopt(3)
All times are GMT -4. The time now is 02:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy