?
Solved

Substring function

Posted on 1999-01-20
4
Medium Priority
?
226 Views
Last Modified: 2010-04-15
Can anyone give me a complete code of the substr function using this parameters. substr( source, start, length ). If any non standard header files are included please include the code also. Planning to implement the function in Red hat linux.
0
Comment
Question by:sanjex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 10

Accepted Solution

by:
rbr earned 400 total points
ID: 1258192
char *substr (char *src,int start,int length)
{
      char *ret;
      ret=calloc (sizeof(char),length+1);
      if (ret) {
            strncpy (ret,src+start,length);
            ret[lentgh]='\0'
      }
      return (ret);
}

0
 
LVL 10

Expert Comment

by:rbr
ID: 1258193
include <string.h>
include <stdlib.h>

0
 
LVL 11

Expert Comment

by:alexo
ID: 1258194
Allocating memory in a function and expecting the caller to free it is an extremely bad practice and a source of countless memory leaks.
0
 
LVL 10

Expert Comment

by:rbr
ID: 1258195
Otherwise he has to give a opointer to the function were to store the string

void substr (char *src,int start,int length,char *dest)
{
    strncpy (dest,src+start,length);
    dest[lentgh]='\0'
}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question