CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    22

    need help in C++

    I have some problems with my program (in C++). Anyone can help me out??


  2. #2
    Join Date
    Apr 1999
    Posts
    5

    Re: need help in C++

    Can you be more specific?


  3. #3
    Join Date
    Apr 1999
    Posts
    22

    Re: need help in C++

    What I need to do is that parsing the given input file for a specific character and then writing the words that were found with that character to the given output file. (both of input and output files are text files).
    I got some source codes from the net. However, it didn't work. Would you mind take a look by any chance. Thank you!

    void LocateCharAux(FILE *pik_in, FILE *TB, TCHAR findchar)
    {

    TCHAR findChar;
    BOOL m_Top = TRUE;
    BOOL m_Bottom = TRUE;

    if (m_Top) {
    findChar = (TCHAR)'T';
    }
    else if (m_Bottom) {
    findChar = (TCHAR)'B';
    }

    if (!pik_in || !TB) return;

    static const TCHAR seps[] = _T(" \t\n");
    TCHAR buf[256];
    TCHAR *token;

    while (fgets(buf, sizeof(buf)/sizeof(buf[0]), pik_in))
    {
    // tokenize the line into words
    token = _tcstok(buf, seps);
    while (token != NULL)
    {
    if (_tcschr(token, findChar) != NULL)
    {
    _ftprintf(TB, _T("%s\n"), token);

    }

    // While there are tokens in "string"
    token = _tcstok(NULL, seps);
    }
    }

    }

    void LocateChar(LPCTSTR text2, LPCTSTR strTB, BOOL bTop)
    {
    TCHAR findChar = bTop ? (TCHAR) 'T' : (TCHAR)'B';

    FILE *pik_in = NULL, *TB = NULL;

    pik_in = _tfopen(text2, _T("r"));

    if (pik_in != NULL) {
    TB = _tfopen(strTB, _T("w"));

    if (TB != NULL)
    {
    LocateCharAux(pik_in, TB, findChar);
    fclose(TB);
    }
    fclose(pik_in);
    }
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured