Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home C-tutorials C String Substring

Related Tutorials


 
 

Share on Google+Share on Google+

C String Substring

Advertisement
In this section, you will learn how to get the substring from a string in C. You can see in the given example, a string and a method substring() is created.

C String Substring

     

In this section, you will learn how to get the substring from a string in C. You can see in the given example, a string and a method substring() is created. Inside the method, we have declared the variables i and j to select the part of the string in order to get the substring. On calling the method substring(6,19,ch), you will get the substring from the specified string. Here 6 and 19 are the starting and ending index values of the string. 

Here is the code:

 

 

 

SUBSTRIN.C

#include <stdio.h>
#include <conio.h>
void substring(int i, int j, char *ch) {
  printf("The substring is: %.*s\n", j - i, &ch[i]);
}
void main() {
  char ch[] "Where there is will,there is a way.";
  clrscr();
  substring(619, ch);
  getch();
}

Output will be displayed as:

SUBSTRIN.EXE

Download Source Code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 6, 2009

Related Tutorials

Discuss: C String Substring   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Johnk512
May 21, 2014


Good website! I truly love how it is easy on my eyes and the data are well written. I'm wondering how I could be notified whenever a new post has been made. I have subscribed to your RSS feed which must do the trick! Have a great day! ekfdkekkdbde
DMCA.com