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

    Not displaying anything

    Hey everyone I am new to this forum. I have a quite puzzling question, I am working on a piece of code that'll take words from a word list and cout them on the screen. I uploaded the file and everything I am using strtok and its using the \n as its delimiters.

    Heres the code-- It did doesn't "cout" anything. Thanks

    #include <iostream>
    #include <string>

    using namespace std;

    int func(char * filePath);


    int main()
    {
    char intake[1024] = {'NULL'};
    cout << "Enter in path of the file.\n";
    cin >> intake;

    func(intake);
    return 0;

    }


    int func(char * filePath)
    {
    FILE * pFile;
    char * x;
    pFile = fopen(filePath, "r");
    while (pFile != NULL)
    {
    x = strtok(filePath, "\n");
    cout << x;
    }

    return 0;
    }

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Not displaying anything

    [ Moved thread ]

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Not displaying anything

    Are you sure it didn't output anything? Maybe it did but it exited before you saw it.

  4. #4
    Join Date
    Feb 2009
    Location
    USA
    Posts
    68

    Re: Not displaying anything

    I just ran your program and this is what printed.
    Code:
    Enter in path of the file.
    F:/Html/htmlfiles/graphics3.htm  /* <-- I entered a file path */
    
    F:/Html/htmlfiles/graphics3.htmF:/Html/htmlfiles/graphics3.htmF:/Html/htmlfiles/graphics3.htm
    F:/Html/htmlfiles/graphics3.htmF:/Html/htmlfiles/graphics3.htmF:/Html/htmlfiles/graphics3.htm
    F:/Html/htmlfiles/graphics3.htmF:/Html/htmlfiles/graphics3.htmF:/Html/htmlfiles/graphics3.htm
    
    /* Infinite loop that continues to print the file path. I only let it run for 20 seconds. */
    I am not sure if i typed the filepath correctly or not? But the infinite loop doesnt seem right.
    Last edited by g.eckert; April 19th, 2009 at 03:30 AM. Reason: Comments in code.
    Google is your friend.

  5. #5
    Join Date
    Mar 2008
    Posts
    30

    Re: Not displaying anything

    You misused strtok. strtok takes a string and a delimiter. It read filePath as a string. I suggest you use fgets and fputs in cstdio.
    Last edited by richard_tominez; April 22nd, 2009 at 11:22 AM.

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Not displaying anything

    Code:
    char intake[1024] = {'NULL'};
    What are you trying to do there?

    and here?

    Code:
    while (pFile != NULL)
    {
    x = strtok(filePath, "\n");
    cout << x;
    }
    There's nothing there that will change the value of pFile.
    Last edited by GCDEF; April 22nd, 2009 at 11:23 AM.

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