Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to get substring

Posted By: Easy Tutor     Category: C Programming     Views: 6738

Write a program that displays a substring of user entered string.

Code for Program to get substring in C Programming

#include <stdio.h>
#include <conio.h>
void main(){
     int m,n,i,len;
     char str[40]="",substr[40]="";
     clrscr();
     printf("*****SubString Demo*****\n\n");
     printf("Enter string : ");
     scanf("%[^\n]s",str);
     for(m=0;str[m]!='\0';m++);

     len = m;

     printf("\nString Extracting Details\n");
     strt:
     printf("enter starting position : ");
     scanf("%d",&m);
     printf("enter ending position : ");
     scanf("%d",&n);

     if(m<=0 || m>len || n<m || n<=0 || n>len){
       printf("\n\nInvalid Input\n\n");
       goto strt;
     }
     else{
    for(i=0;m<=n;m++,i++)
       substr[i]=str[m-1];
    substr[i]='\0';
    printf("\nSub String is %s",substr);
       }

   getch();
}
  
Share: 


Didn't find what you were looking for? Find more on Program to get substring Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program to get substring is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!