User Profile

Collapse

Profile Sidebar

Collapse
sandvet03
sandvet03
Last Activity: Apr 3 '08, 10:11 AM
Joined: Mar 28 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • need help! replacing substing in a string with another substring

    I am trying to expand on a earlier program for counting subs and now i am trying to replace substrings within a given string. For example if the main string was "The cat in the hat" i am trying to find a chosen substring lets say "cat" and then replace it with a difrent inputed substring say "dog". Tried to get as far as i could on my own but need some help, sugestions, snippets or guidence.

    [code=c]...
    See more | Go to post

  • sandvet03
    replied to help with counting substings in strings???
    in C
    Thanks for the help i have it figured out with the suggestions, below is a chunk of the code i needed to add, hope others others can learn from it.
    [code=c]
    char *q;//pointer
    int count=0; for (i=0;i<length;i ++)
    q[i]=subcap[i];
    q=strstr(q+1,s2 );
    q=strstr(s1,s2) ;
    while (q!= NULL)
    {q=strstr(q+1,s 2);
    count++;}//counter
    [/code]
    See more | Go to post

    Leave a comment:


  • sandvet03
    replied to help with counting substings in strings???
    in C
    No help yet? can anyone tell me where the return value from the strstr goes and am i able to check to see if it is null or not by if statments? Further does the return value to the array need to be 0 or should it be a pointer to s1 or s2?...
    See more | Go to post
    Last edited by Ganon11; Mar 30 '08, 09:41 PM. Reason: Fixing [CODE] tags.

    Leave a comment:


  • sandvet03
    started a topic help with counting substings in strings???
    in C

    help with counting substings in strings???

    Im a newby to programing 2 months exp.. I am trying to write code in C to take a input string from the user and then the input substring. I wish to compare the substring to the string and count the number of times it apears and print this to the user. After many hours of frustration i have gotten this far any help or derection would be aprieciated [code=c]
    # include<stdio.h >
    # include<math.h>
    # include<stdlib. h>...
    See more | Go to post
No activity results to display
Show More
Working...