C Programming_(C Preproccessor & Command Line Argument) - EDUREJA

Latest News

C Programming_(C Preproccessor & Command Line Argument)

C Programming
2 programs with Solution & Output
Rejaul Hoque Sarkar
Cont. No.- 9749189618 ; Email ID- srejaulhoque@gmail.com
------------------------------------------------------------------------------------------------------------------
Download our Android Mobile App

Click Here ==>> Download

------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------

1/ Write a C program to find the biggest of given two numbers using macros.
Solution :=:>

#include <stdio.h>
#include <conio.h>
#define BEGIN {
#define END   }
#define BIG(a,b) ((a > b) ? a : b)
#define WAIT getch();
#define WAITMSG "\n Press any key to continue..."
void main()
   BEGIN
      int x,y;
      clrscr();
      printf("\n Enter two integers : ");
      scanf("%d %d", x, y);
      printf("\n Biggest integer is %d", BIG(x,y));
      printf("\n %s", WAITMSG);
      WAIT
   END

Output :=:>
---------------------------------------------------------------
Enter two integers : 5 8
Biggest integer is 8
Press any key to continue...
---------------------------------------------------------------

2/ Write a C Program using command line arguments.
Solution:=:>

#include <stdio.h>
#include <conio.h>
void main(int argc, char *argv[])
{
      char ch;
      FILE*source_fptr,*target_fptr;
      if (arch != 3)
      {
            printf("\n Number of arguments insufficient !!!");
            Printf("\n    Press any key to continue...");
            getch();
            exit();
      }
      source_fptr = fopen(argv[1],"r");
      target_fptr = fopen (argv[2], "w+");
      if(source_fptr == NULL)
      {
            printf("\n No content/source file !!!");
            printf("\n    Press any key to continue...");
            getch();
            exit();
      }
      printf("\n copyright source file %s to target file %s, argv[1], argv[2]");
      printf("\n please wait...");
      delay(20000); printf(".");
      delay(20000); printf(".");
      delay(20000); printf(".");
      delay(20000); printf(".");
      delay(20000); printf(".");
      /*loop to copy the text file*/
      while(!feof(source_fptr))
      {
            ch = getc(source_fptr);
            putc(ch,target_fptr);
      }
      if(target_fptr == NULL)
      {
            printf("\n No content/target file !!!");
            printf("\n\n    Press any key to continue...");
            getch();
            exit();
      }
      printf("\n\n Copy completed, the target file contents");
      printf("---------------------------------------------");
      rewind(target_fptr);
      while(!feof(target_fptr))
      {
            ch = getc(target_fptr);
            printf("%c", ch);
      }
      fclose(source_fptr);
      fclose(target_fptr);
      printf("\n\n Pressany key to continue...");
      getch();
}

Output :=:>
---------------------------------------------------------------------------------------
C:\turbo>COPYFILE SAMPLE.TXT  SAMPLE.BAK
Copying sourcefile SAMPLE.TXT to target file SAMPLE.BAK
Please wait ...
Copy completed, the target file contents
----------------------------------------

Computer programming inC language is widely used for
Science and Engineering applications.

Press any key to continue...
C:\turboc>

---------------------------------------------------------------------------------------




_______________________________________________________________________
------------------------------------------------------------------------------------------------------------------
Download our Android Mobile App

Click Here ==>> Download
------------------------------------------------------------------------------------------------------------------


Thank You,
EduReja


Like us on Facebook : FB

Follow us on Twitter : TW
-----------------------------------------------------------------------------
See our another C Programming Page, Click Here ==> 1  2  3 4
-----------------------------------------------------------------------------
See Our Videos ==>> CLICK HERE
See Our Videos ==>> CLICK HERE
  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment

Item Reviewed: C Programming_(C Preproccessor & Command Line Argument) Description: Rating: 5 Reviewed By: Rejaul Hoque Sarkar
Scroll to Top