Posts

My Subject Blog

C Program Upper to Lower and Lower to Upper Case

/*  Write a C Program to Conver all Character of String from upper to lower and lower to upper case.  */ #include <stdio.h> int main(void)  { char str[20]="aBcDeF"; int i=0; while(str[i]!='\0') { str[i]=str[i]^32;                 //Above Logic will convert character upper to Lower and lower to upper i++; } printf("Changed String : %s",str); return 0; }

C Program Welcome Print

/*Write a Program to display “ WELCOME TO SILVER OAK INSTITUTE OF TECHNOLOGY ” on the screen.*/ #include <stdio.h> int main(void) { printf("WELCOME TO SILVER OAK INSTITUTE OF TECHNOLOGY"); return 0; }

C Program for FILE Function fputc fputs fgets

/* Write a program to illustrate the use of fputc(), fputs(), and fgets(). */ #include<stdio.h> #include<string.h> int main()  {      FILE *fp;  char str[4];  char ch[4]={'a','b','c','d'};  int i;  fp=fopen("Test.txt","w");  if(fp == NULL)   {   perror("Error opening file");   return(-1);  }  for(i=0;i<4;i++)  { fputc(ch[i],fp); //use of fputc()  }  fputs("EFGH",fp);    //use of fputs()  fclose(fp);      fp=fopen("Test.txt","r");   if(fp == NULL)   {   perror("Error opening file");   return(-1);  }   while(fgets(str,4,fp)!=NULL)   //use of fgets()  { printf("%s",str);  }  fclose(fp);     return 0; } 

C Program for Basic File Operation

/* Write a program to create a file and perform basic I/O operations on the same.  */ #include<stdio.h> int main()  {     FILE *fp;     int ch;     fp=fopen("Test.txt","w");     if(fp == NULL)  { perror("Error opening file"); return(-1); } putc('A',fp);     fclose(fp);        fp=fopen("Test.txt","r"); if(fp == NULL)  { perror("Error opening file"); return(-1); }  ch=getc(fp);     printf("CHAR = %c",ch);     fclose(fp);     return 0; } 

C Program for Memory Allocation and Reallocation

/* Write a program to store a character string in a block of memory space created by malloc and then modify the same to store a large string. */ #include <stdio.h> #include <stdlib.h> int main(void)  { char *ch; int n,n1; printf("\n Enter Size of String you Want : "); scanf("%d",&n); if((ch = (char *)malloc(n *sizeof(char))) == 0)         {             printf("\n No space available");             exit(1);         }     else       {           printf("\n %ld Bytes Space are allocated Successfully", n * sizeof(char));       }     printf("\nEnter String :");     scanf("%s",ch);     printf("\n String is : %s",ch);     printf("\n Enter Size You Want Increase: ");     scanf("%d",&n1);     if((ch = (char *)realloc(ch,(n+n1) *sizeof(char))) == 0)         {             printf("\n No extra space available");          

C Program for Runtime Memory Allocation for Table of Integers

/* Write a program that uses a table of integers whose size will be specified interactively at runtime.  */ #include <stdio.h> #include <stdlib.h> int main() {     int *p;     int n,i;     printf("\nEnter the size of table : ");     scanf("%d",&n);     if((p = (int*)malloc(n *sizeof(int))) == 0)        {            printf("\n No space available");            exit(1);        }    else       {          printf("\n %ld Bytes Space are allocated Successfully", n * sizeof(int));       }    for(i=0;i<n;i++)    {     printf("Enter Value for Position : [%d]",i+1);     scanf("%d",(p+i));    }    printf("\n Values in Reverse \n ");     for(i=n-1;i>=0;i--)    {     printf("\n Position [%d] Value is : [%d]",i+1,*(p+i));    } return 0; }

Followers