visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: General :: C Substring Function


By: progGoon U.S.A.  Date: 26/04/2003 00:00:00  English  Points: 75 Status: Answered
Quality : Excellent
I've been trying to do this code and it seem not to work and I need your help. This is in C programming only not C++.

I need to write a function for substring with four parameters: str, substr, i and len. The parameters str and substr are char arrays.
The outcome will be:
Enter a string: The cat sat on the mat
i is 8
len is 3
the string will be sat
By: VGR Date: 27/04/2003 05:36:00 English  Type : Answer
tips :

// tokenize on space delimitor may help, a single for loop would do.
// else, the dirty way :
result="";
i=strpos(str,substr);
if (i) {
j=strpos(substr(str,i)," "); // right part
j=j+i; // real position in first string
result=substr(str,i,j-i+1);
// in case you need it, length is strlen(result);
}
return result;
By: FiatLink Date: 27/04/2003 19:08:00 English  Type : Comment
<A HREF="http://home.work.not/done/here.html">http://home.work.not/done/here.html</a>

please post code what you have done so far
By: collegeBoy Date: 27/04/2003 19:32:00 English  Type : Assist
void substr(char* str, char* substr, int start, int len)
{
strncpy(substr, str + start, len);
substr[len] = '\0';
}
By: progGoon Date: 03/05/2003 15:44:00 English  Type : Comment
Write a function substring with four parameters: str, substr, i and len. The parameters str and substr are char arrays. The parameters i and len are ints. The function substring normally copies len consecutive characters from str, beginning at index i, into substr. If the null terminator is encountered in str, the function will stop copying characters into substr. Assume that substr is large enough to hold the characters copied and the null terminator.

Example:
The string is: The cat sat on the mat
i is 8
len is 3
after running function, substr will be: sat

Do register to be able to answer

EContact
browser fav
page generated in 349.231960 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page