Solved

"-f"

Posted on 2003-10-24
5
266 Views
Last Modified: 2010-04-22
This is my code:

#include <stdio.h>

int main()
{
      FILE *fptr;
      char buffer[80];
      fptr = fopen("data.txt","r");
      if(fptr == NULL)
      {
              printf("Error");
              exit(1);
      }
      else
      {
              while(fgets(buffer,80,fptr))
              {
                     printf("%s",buffer);
              }
              fclose(fptr);
       }
}      


Is there a way to execute this program with the first parameter as the
"-f" and the second parameter as the name of the textfile?. Then
the program will read the contents of the textfile and display.

Do we incoperate the -f as part of the program. Does it do any sort of validation or functionality. Please include some examples.

P.S I know the command line arguments.

Regards
Eugene
0
Comment
Question by:eugene007
  • 2
5 Comments
 
LVL 3

Expert Comment

by:scn
ID: 9615055
man 3 getopt   (an example is included in the manpage)
0
 

Author Comment

by:eugene007
ID: 9618274
can u further explain, cause I dont have linux on my machine.
0
 
LVL 3

Expert Comment

by:scn
ID: 9619405
0
 

Accepted Solution

by:
RomMod earned 0 total points
ID: 11560631
Closed, no points refunded.
RomMod
Community Support Moderator
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now