Solved

"-f"

Posted on 2003-10-24
5
272 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

770 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