Tutorialspoint

srand() in C language

c

#include <stdio.h>
#include<stdlib.h>
#include<time.h>
int main() {
   srand(time(NULL));
   printf("%d\n", rand());
   srand(12);
   printf("%d", rand());
   return 0;
}

strndup() in C language

c

#include <stdio.h>
#include<string.h>
int main() {
   char *str = "Helloworld";
   char *result;
   result = strndup(str, 3);
   printf("The string : %s", result);
   return 0;
}

rand() in C language

c

#include <stdio.h>
#include<stdlib.h>
int main() {
   printf("%d\n", rand());
   printf("%d", rand());
   return 0;
}

strdup() in C language

c

#include <stdio.h>
#include<string.h>
int main() {
   char *str = "Helloworld";
   char *result;
   result = strdup(str);
   printf("The string : %s", result);
   return 0;
}

fflush(stdin) in C language

c

#include <stdio.h>
#include<stdlib.h>
int main() {
   char s[20] = "Helloworld";
   printf("The string : %s", s);
   fflush(stdin);
   return 0;
}

ispunct() in C language

c

#include <stdio.h>
#include<ctype.h>
int main() {
   int a = '!';
   int b = 'a';
    
   if(ispunct(a))
      printf("The character is a punctuation.");
   else
      printf("\nThe character is not a punctuation.");
         
   if(ispunct(b))
      printf("\nThe character is a punctuation.");
   else
      printf("\nThe character is not a punctuation.");
   return 0;
}

strspn() in C language

c

#include <stdio.h>
#include<string.h>
int main() {
   const char s1[] = "Helloworld!";
   const char s2[] = "Hello";
   int length = strspn(s1, s2);
   printf("The length of string : %d", length);
   return 0;
}

strcoll() in C language

c

#include <stdio.h>
#include <string.h>
int main () {
   const char s1[] = "Helloworld";
   const char s2[] = "Blank";
   char *result;
   result = strcoll(s1, s2);
   
   if(result > 0)
      printf("String s1 is greater than string s2");
   else if(result < 0)
      printf("String s1 is less than string s2");
   else
      printf(" Strings are not same");
   return(0);
}

strpbrk() in C language

c

#include <stdio.h>
#include <string.h>
int main () {
   const char s1[] = "Helloworld";
   const char s2[] = "Blank";
   char *result;
   result = strpbrk(s1, s2);
   printf("The matching character : %c\n", *result);
   return(0);
}

Compile and Execute C Online

c

#include <stdio.h>
#include <stdlib.h>
int main () {
   char str1[10];
   int year;
   FILE * fp;
   fp = fopen ("file.txt", "w+");
   fputs("This is demo text!", fp);
   rewind(fp);
   fscanf(fp, "%s", str1);
   printf("First word = \n%s\n", str1 );
   fclose(fp);
   return(0);
}

1 2 3 4 5 6 7 ... 52 Next
Advertisements
Loading...