c command line program code using argv
#include<stdio.h>
void main( int arge,char *argv[])
{
FILE * fp;
int i;
char word[15];
fp=fopen(argv[1],"w");
printf("\nNo.of argument in command line=%d\n\n",arge);
for(i=2;i<arge;i++)
fprintf(fp,"%s",argv[i]);
fclose(fp);
printf("contents of %s file\n\n",argv[1]);
fp=fopen(argv[1],"r");
for(i=2;i<arge;i++);
{
fscanf(fp,"%s",word);
printf("%s",word);
}
fclose(fp);
printf("\n\n");
for(i=0;i<arge;i++)
printf("%*s \n",i*5,argv[i]);
}
Example for:-c command line program code using argv
#include<stdio.h>
void main( int arge,char *argv[])
{
FILE * fp;
int i;
char word[15];
fp=fopen(argv[1],"w");
printf("\nNo.of argument in command line=%d\n\n",arge);
for(i=2;i<arge;i++)
fprintf(fp,"%s",argv[i]);
fclose(fp);
printf("contents of %s file\n\n",argv[1]);
fp=fopen(argv[1],"r");
for(i=2;i<arge;i++);
{
fscanf(fp,"%s",word);
printf("%s",word);
}
fclose(fp);
printf("\n\n");
for(i=0;i<arge;i++)
printf("%*s \n",i*5,argv[i]);
}
Example for:-c command line program code using argv
0 comments: