Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,101 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,682 people online right now. Registration is fast and FREE... Join Now!




files

 
Reply to this topicStart new topic

files, opening and printing

WannabeNerdy
3 Oct, 2007 - 12:25 PM
Post #1

New D.I.C Head
*

Joined: 3 Jul, 2007
Posts: 21


My Contributions
Just want to make sure I am doing this right. I want to open a file already created by the user, open it and then print it on the screen. I'm not really certain as to what to put in the fprintf because the text file is (of coarse) all strings. There's whitespace, and different lines to think about, and by now i'm just confuzzled.

CODE

#include <stdio.h>
#include <stdlib.h>


main ()
{
      
    FILE *fp;
    char file[100];
    
    printf ("Enter a filename to load: ");
    scanf ("%s" , &file);
    
    fp = fopen(file, "r");
    
    fprintf("          //just type the file name?
    
    system ("PAUSE");
    return;
}


User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Files
3 Oct, 2007 - 12:28 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,441



Thanked: 64 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
As per :http://www.cplusplus.com/reference/clibrar...io/fprintf.html
CODE

/* fprintf example */
#include <stdio.h>

int main ()
{
   FILE * pFile;
   int n;
   char name [100];

   pFile = fopen ("myfile.txt","w");
   for (n=0; n<3; n++)
   {
     puts ("please, enter a name: ");
     gets (name);
     fprintf (pFile, "Name %d [%-10.10s]\n",n,name);
   }
   fclose (pFile);

   return 0;
}

User is online!Profile CardPM
+Quote Post

WannabeNerdy
RE: Files
3 Oct, 2007 - 02:48 PM
Post #3

New D.I.C Head
*

Joined: 3 Jul, 2007
Posts: 21


My Contributions
That bit of code is pretty sweet. I would have never thought of the last part.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:57PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month