Showing posts with label function in c programming. Show all posts
Showing posts with label function in c programming. Show all posts

Saturday, March 6, 2021

, , , , ,

Example program for isxdigit() function in c

 The isxdigit() function in c programming checks whether a character is a hexadecimal digit character (0-9, a-f, A-F) or not.

Syntax for isxdigit in c :-

int isxdigit( int arg );

 isxdigit() Parameters

The isxdigit() in c takes a single character as it's parameter.

 C isxdigit() Return Value

 if passed argument is an hexadecimal character then isxdigit() return non-zero integer otherwise return 0.

Example program for C isxdigit() function


#include <ctype.h>
#include <stdio.h>

int main() {
   char c = '5';
   int result;

   // hexadecimal character is passed
   result = isxdigit(c); // result is non-zero
   printf("Result when %c is passed to isxdigit(): %d", c, isxdigit(c));

   c = 'M';

   // non-hexadecimal character is passed
   result = isxdigit(c); // result is 0

   printf("\nResult when %c is passed to isxdigit(): %d", c, isxdigit(c));

   return 0;
}

OUTPUT : - 



C isxdigit()
C isxdigit()

, , , , ,

Example program for ispunct in c

 The ispunct() function in c programming checks whether a character is a punctuation mark or not.

Syntax for ispunct() in c

int ispunct(int argument);

it returns a non-zero integer if given characters to ispunct() in c is an punctuation otherwise return 0.

Example for Program to check punctuation with the help of ispunct() function in c:-

#include <stdio.h>
#include <ctype.h>

int main() {
   char c;
   int result;

   c = ':';
   result = ispunct(c);

   if (result == 0) {
      printf("%c is not a punctuation", c);
   } else {
      printf("%c is a punctuation", c);
   }

   return 0;
}

 Output

ispunct
ispunct in c

 

 

Thursday, December 17, 2020

, , ,

fopen function in c programming with it's example

 fopen c function is used to open a file which is denoted by the file name in c programming.

Syntax for fopen function in c : -

FILE *fopen(const char *filename, const char *mode)

Parameters For for fopen c : -


filename : - this element contain the file name which is going to be open.

Mode :- This string in c contain the method to access the file.

Check the mode for open a file in c programming with the help of fopen c function. 

  • "r" Mode : - This mode opens a file for reading.
  • "w" Mode : - this one use to create a empty file for writing.
  • "a" Mode : - It use to append the data  at the end of the file.
  • "r+" Mode : - This mode open a file to make an update in reading and writing.
  •  "w+" Mode :  - Create an empty file for both reading and writing.
  •  "a+" Mode : - Use to open an file for appending and also for reading.

Return Value for fopen c function : -

  •  fopen function in c return a file pointer otherwise give a null.
  • errno global variable is used to indicate the error in fopen function.

Example program for fopen function in c :

#include <stdio.h>
#include <stdlib.h>

int main () {
   FILE * fp;

   fp = fopen ("file.txt", "w+");
   fprintf(fp, "%s %s %s %d", "We", "are", "in", 2012);
   
   fclose(fp);
   
   return(0);
}


Example for fopen c
Example program for fopen c