Thread: Program works for stdin but fails for a file.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    10

    Program works for stdin but fails for a file.

    I am studying data structures and was asked to build a program that uses a stack to reverse lines of text. Here it is: https://pastebin.com/raw/CGq6ZaHM

    The problem is: it works for the stdin (when I redirect some input into it), but when I call it with a file as argument, the following error appears:

    Code:
    free(): invalid pointer
    I could not find how free gets a invalid pointer from using getc(fp) instead of getc(stdin).
    Can someone help me find the error?
    Last edited by felixthunder; 03-21-2020 at 02:21 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-20-2014, 03:04 PM
  2. Compile under gcc fails, but VS2010 works
    By Sorin in forum C++ Programming
    Replies: 11
    Last Post: 01-20-2012, 02:45 AM
  3. This works fine with IP 127.0.0.1 but fails with my REAL IP.
    By azjherben in forum Networking/Device Communication
    Replies: 15
    Last Post: 05-19-2009, 10:28 PM
  4. Replies: 6
    Last Post: 05-08-2009, 08:51 PM
  5. Replies: 5
    Last Post: 04-13-2009, 09:55 AM

Tags for this Thread