Thread: Need help with C++ lab program

  1. #1
    Unregistered
    Guest

    Need help with C++ lab program

    My teacher has assigned us a problem in which we have to write a program that prints itself. The program must use file pointer. Below is what I have done so far:

    #include <stdio.h>
    main ()
    {
    FILE *fp;
    fp = fopen("filename.c", "r");
    fclose (fp);
    }

    Can you tell what I am missing? When I execute I get a funny symbol. Any help is appreciated.

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    Maybe use C++?

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    int main()
    {
         string Indata;
         istream ins("filename.cpp");
         while (!ins.eof()) {
               ins >> Indata;
               cout << Indata;
         }
         return (0);
    }
    Last edited by rmullen3; 02-25-2002 at 12:51 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM