C program for file operations that stores and numbers of alphabets in files and display it

In this I will tell you how to operate on file . And how to print alphabets in a text file to our program's to output . So without any further delay let's get started . First I will let you know the code then 

come to explanation .

Code:

#include <stdio.h>

int main()
{
  FILE *ptr;
  char ch;
  ptr = fopen("alpha.txt""r");

  while (1)
  {
    ch=fgetc(ptr);
    if(ch==EOF){
      break;
    }
   printf("%c", ch);
   
  }
  printf("\n");
  fclose(ptr);

  return 0;
}

Screenshot of text file :

here we write alphabet in txt file 
Logic :
for our program we need to create a text file . Here I create file name alpha.txt. Here we first make pointer which points towards file ptr.  And a variable ch of type character so that it can get character from file in it . And then we open a file using Fopen.  And open file in reading mode . And then we run a infinite loop and our only come out form it only when ch is equal to EOF(end of file) and break take him out of loop  . And in variable ch we assign character to it with the help of Fgetc function . And input to this function is ptr which points towards file .  And after doing all this we close our file by closing pointer .

Output:



Now you can see that our program operates on file as accepted and print every alphabet on file . So I think that it helpful in your work .  If you do not want to miss Interesting program then can follow our blog . And can read other useful programs below .
Thanks for reading 









Temperature Converter using C Language

 In this  I will tell you how to make temperature Converter using C language . So, without wasting   our  time let's get started with our today's  topic .  Let us first see the code then we understand logic and then    output.

Code:

#include <stdio.h>
int main()
{
    float inputTemp;
    char inputType;
    char outputType;
    float outputTemp;
    printf("Enter the unit for input (k for Kelvin, F for Fahernite ,C for Celcius)\n");
    scanf(" %c", &inputType); 
    printf("Enter the value for input \n");
    scanf("%f", &inputTemp);
    printf("Enter the unit for output (k for Kelvin, F for Fahernite ,C for Celcius)\n");
    scanf(" %c", &outputType);                //for output value
    if (inputType == 'c' || inputType == 'C'//when input type is Celsius
    {
        if (outputType == 'f' || outputType == 'F')
        {
            outputTemp=(inputTemp *9/5)+32;
            printf("Temperature in Fahernite : %.2f ", outputTemp);
        }
        else if (outputType == 'K' || outputType == 'k')
        {
            outputTemp = inputTemp + 273.15// from Celcius to Kelvin
            printf("Temperature in Kelvin : %.2f", outputTemp);
        }
    }
    if (inputType == 'f' || inputType == 'F')
    { //when input type is Fahernite
        if (outputType == 'C' || outputType == 'c')
        {
            outputTemp = (inputTemp - 32) * 5 / 9
            printf("Temperature in Celcius: %.2f", outputTemp);
        }
        else if (outputType == 'K' || outputType == 'k')
        {
            outputTemp = (inputTemp - 32) * 5 / 9 + 273.15
            printf("Temperature in Kelvin: %.2f", outputTemp);
        }
    }
    if (inputType == 'K' || inputType == 'k')
    {  //when input is in Kelvin 
        if (outputType == 'F' || outputType == 'f')
        {
            outputTemp = (inputTemp - 273.15) * 9 / 5 + 32;
            printf("Temperature in Fahernite : %.2f", outputTemp);
        }
        else if (outputType == 'C' || outputType == 'c')
        {
            outputTemp = inputTemp - 273.15;
            printf("Temperature in Celcius: %.2f", outputTemp);
        }
    }
    return 0;
}

Logic:

Here we first define two variable of type float to take input Temperature and give output Temperature that is inputTemp and outputTemp. And then we define two variable of type Char to take Character of unit in which we want to give input to program(inputType) and then for output we use (outputType). And after taking these values we first check make all case that can be possible if input in Celsius  and in outputTemp variable we assign formula that we need to convert Celsius  into Fahrenheit and if user want output in Kelvin then we use formula to Celsius into Kelvin. And we did same if  input is in Kelvin  or in Fahrenheit . And alter only formula and done with our work . You can check for formula on internet . 

Output:




      now here you can see that our program work great . As we give 0 input it give output as we desired           in another unit .

     I hope this will help you in your work .

     Thanks for reading .


Customer bill in C program

 In this post I will let you know how to make bill proper bill program for ration shop or any other store .     Made your own Algebraic Calculator, So, without any further delay let's get started .

Code:

#include <stdio.h>
#include<string.h>

int main()
{
    int  noi;          //noi is for number of items
    int  itemnum[100]; // it  is for number of items
    float price[100];   //price of one item
    float total = 0;
    char name[40];
    char date[10];
     char product_name[20][20];
    printf("Enter name of Customer \n");
    gets(name);
    printf("Enter date\n");
    gets(date);
    printf("Enter number of products purchased \n");
    scanf("%d",&noi);
    for (int i = 0; i < noi; i++)
    {
        printf("Enter  item number  \n");
        scanf("%d", &itemnum[i]); 
        printf("Enter name of product\n");
        scanf("%s",product_name[i]); 
        printf("Price of item first %d \n", i + 1);
        scanf("%f", &price[i]);
    }
   for(int i=0;i<noi;i++){
       total=total+price[i];
   }
   printf("Customer name:\t%s\tDate:\t%s\n",name,date);
   printf("Product name\tProduct number\tProduct price \n");
   for(int i=0;i<noi;i++){
       
        printf("%s\t\t",product_name[i]);
        printf("\t%d\t",itemnum[i]);
      printf("\t%f\t\n",price[i]);
   }
   printf("----------------------------------------\n");
   printf("Total price :\t%f\n",total);
   printf("Thanks for shopping\n");

    return 0;
}

Logic:

Here we first we declare  noi (number of items) of type int .Then we make one array of type float that is  price . And itemnum (item number) array of type int.And then we  declare two array of type char name (to get name of customer) ,and date (for which date bill is make ). And then we make two dimensional string of product_name (to take name of item purchased). Then using for loop we take input of three arrays namely itemnum , price, product_name. And it take input  till it is less than noi .As I told you above .Then we again use for loop to get total bill of customer . And in last for loop we print given value by user . Then total bill of customer . 

Output:


Here you can see output and I think you may find this helpful in your work . 

   Thanks for reading