Need help with C++ lab program

This is a discussion on Need help with C++ lab program within the C++ Programming forums, part of the General Programming Boards category; My teacher has assigned us a problem in which we have to write a program that prints itself. The 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, 01: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, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21