Thread: array function(a tiny problem)

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    11

    array function(a tiny problem)

    i'm having trouble getting the right output: it should be 3LU$CH

    #include<iostream.h>
    #include<string.h>

    void main()
    {
    int index(char *,char);
    char line[30]="LUNCH";

    cout<<index(line, 'N')<<" "<<line<<endl;
    }



    this function will replace the 1st occurance of ch by a dollar sign and return teh posiiton where the occurrence is found. It returns a zero value if ch is not found.

    int index(char*s, char ch)
    {
    ******this is the part that needs to be done. I used the strncat function but it didnt work******
    }
    please provide some guidance and i'd b xtreemly grateful to you.thanx.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    1. Use the strchr function to find a char in a string.

    2. main returns an int
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Dynamically Increasing Array of Integers
    By laserlight in forum C++ Programming
    Replies: 30
    Last Post: 07-04-2008, 07:27 AM
  2. Array problem
    By TomBoyRacer in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2007, 11:35 AM
  3. Replies: 6
    Last Post: 02-15-2005, 11:20 PM
  4. Problem Putting INTs Into a CHAR Array
    By cram in forum C++ Programming
    Replies: 13
    Last Post: 10-13-2004, 07:53 AM
  5. Need desperate help with two dimensional array problem
    By webvigator2k in forum C++ Programming
    Replies: 4
    Last Post: 05-10-2003, 02:28 PM