Solved

"-f"

Posted on 2003-10-24
5
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Shell script awk command 2 123
GUI development for Ubuntu 8 225
stopping a java process started with daemon command 2 83
Error while installing rpm 1 93
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

751 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