Showing posts with label Strings. Show all posts
Showing posts with label Strings. Show all posts

How to remove any character from string in c

 In this I will tell you how to remove any character from the given String in C . So without any further delay let's get started .

Code:

#include<stdio.h>
#include<string.h>
//how to remove any character from string in c
int main(){
    char str[100];
printf("Enter the string \n");
    scanf("%[^\n]s",str);
  int j = 0;
    for(int i=0;str[i]!='\0';i++){
           if (str[i] == 'a')
        {
         str[j++]=str[i+1];  
         i++
        }
        else{
         str[j++]=str[i];
        }
        
    }
str[j]='\0';
    printf("%s  ",str);
    return 0;
}

Logic:

Now that we have see the code let's understand one by one . First of all we created a String of length 100 . And named it str . Then with the help of printf function we print user message to Enter the string . And then with help of scanf function  taking  String  as input. From the user .  And then we use a for loop and  run it till the end of the String. And we also declare variable j and initialize it from 0. For indexing of the same String after that character is removed . Then we take use   if-else  and in if condition we check for str[i]== 'a' if found then character after that is copied  in str[j++] else it copy before it is copied in str[j++]=str[i]  . And then after doing all this we end the String with '\0'.

Output:


And here you can see that our program work correctly and remove character 'a' from the String . Try this program by yourself and please provide me feedback by commenting your opinion . I hope that you find this helpful in your work. 

                                                              Thanks for reading  








School fee management program using C language

 In this I will let you know how to write a program that manage school without using any complication . So , without wasting our let's get started .  First I show you code then we come to explanation .

Code:

#include <stdio.h>
//School fees management program using C languag

int main()
{
    //For Students Details
    char SchoolName[30];//School Name
    char Date[10];//To get date 
    int Eno;        //Student Enrollement
    char Sname[20]; //Student Name
    char Fname[20]; //Student's Father's Name
    char Mname[20]; //Student's Mother's Name
    char C_S[10];   //Class and Section
    //Now for fees details
    int CMF; //Consoliated Monthly fees
    int R_f; //Readmission and fine
    int Conveyance;//If you use bus 
    int Tfess;//Term fees 
    int Cfess;//Computer fees
    int Exam;//Exam fees
    int Rfess;//Registration fees
    int Afess;//Admission fees 
    int concession;//Concession fees 
    int grTotal;//grand Total
    printf("Enrollenment no.\n");
    scanf("%d",&Eno);
    printf("School name\n");
    scanf(%[^\n]s",SchoolName);
    printf("Date\n");
    scanf(%[^\n]s",Date);
    printf("Student name\n");
    scanf(%[^\n]s",Sname);
    printf("Father's Name\n");
    scanf(%[^\n]s",Fname);
    printf("Mother's Name\n");
    scanf(%[^\n]s",Mname);
    printf("Class & section\n");
    scanf(%[^\n]s",C_S);
    printf("Consilated Monthly Fees:\n");
    scanf("%d",&CMF);
    printf("Readmission/Fine: \n");
    scanf("%d",&R_f);
    printf("Conveyance: \n");
    scanf("%d",&Conveyance);
    printf("Term Fees: \n");
    scanf("%d",&Tfess);
    printf("Computer fees: \n");
    scanf("%d",&Cfess);
    printf("Exam fees: \n");
    scanf("%d",&Exam);
    printf("Registration Fees: \n");
    scanf("%d",&Rfess);
    printf("Admission Fees :\n");
    scanf("%d",&Afess);
    printf("Concession: \n");
    scanf("%d",&concession);
    grTotal=(CMF+R_f+Conveyance+Tfess+Cfess+Exam+Rfess+Afess)-(concession);
    //Grandtotal is sum of all subract concession 
     printf("Date:%s     School Name :%s\n",Date,SchoolName);
     printf("Enrollement No.%d         Student Name:%s   Class & Section: %s\n",Eno,Sname,C_S);
     printf("Father's Name:%s            Mother's Name:%s\n",Fname,Mname);
     printf("------------------------------------------------------------------------------\n");
     printf("Consilated Monthly Fees : %d\t\t Readmission/fine :%d\n",CMF,R_f);
     printf("Conveyance fees :%d\t\t Term Fees : %d\n ",Conveyance,Tfess);
     printf("Computer fees : %d \t\t Exam fees :%d\n",Cfess,Exam);
     printf("Registration fees : %d \t \t Admission fees :%d\n ",Rfess,Afess);
     printf("Concession : %d\n");
     printf("----------------------------------------------------------------------------------\n");
     printf("Grand Total : %d \n",grTotal);

    return 0;
}

Logic:

Here we first declare  the variables for the details of the students . Namely SchoolName , Date, Sname(Student's Name), Fname(father's Name), Mname(mother's Name), C_S(class & section)  of type character array(String) and  Eno(Enrollement No) of type int. And then we  define variables for fees details of the students . I just define variables for only few important fees details you can customize it according to yours . Here two important variables is necessary that is grTotal(grand Total) of fees and Concession . And then we take input to these variables for int data type taking input is easy . And for String  we take input using special method  About input in String . And then we do grandTotal of fees by adding other charges  and subtract concession from it . And then we just use printf statement and to show user  fees summary of student.

Output:


here you can see that we give input as required . And then we get our desired output . This tells us that our program work properly. Try this by self by changing the variables . Please provide feedback  this code by commenting  your views.  I hope this is helpful in your work . Thanks for reading.