File access, argc, argv[]

Source: Internet
Author: User

_____main function contains two parameters, ARGC, argv[]

These two parameters are used to indicate the parameter information entered by the command line.

The value of the ARGC is the number of input parameters. ARGV is an array in which each array element points to the address of a string type of data, that is, the address of each input parameter. ARGV is a char * * type.

voidFileCopy (FILE *ifp,file *OFP) {    intC;  while((c = getc (IFP))! =EOF)    {PUTC (C,OFP); }}intMainintargcChar*argv[]) {    //Practice file Access//practice argc, argvFILE *FP; if(ARGC = =1)//no args;copy standard input{fileCopy (stdin, stdout); }    Else{printf ("%d\n", ARGC);  while(--ARGC >0)        {            inti;  for(i =0; i < argc; i++)//parameter is a string. {printf ("%s%s", Argv[i], (I < argc-1) ?" ":""); } printf ("\ n");/*When parameter is a file name.                if (fp = fopen (*++ARGV, "R")) = = NULL) {printf ("can ' t open%s\n", *argv);            return 1;                } else {fileCopy (fp,stdout);            Fclose (FP); }*/        }    }    return 0;}

___file Access

fprintf, fscanf corresponds to the standard input and output of printf and scanf, the parameter is more than the first one of the file type parameters.

File type

File access, argc, argv[]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.