output to screen 
Author Message
 output to screen

I use this code to copy files to files and to screen. When I try to write
any formatted text out of a word document to screen the results are just a
series of a's, I presume my text editor can't handle the formatting.

I would like to know what the a's are, and also is there any way of opening
the documents from C, like opening applications and documents from DOS.
Thankyou, Ian.

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

int file_copy(char *oldname,char *newname);

int main()
{

     char ch,source[40],destination[40];

     printf("Enter a source filename: ");
     gets(source);
     printf("Enter destination filename: ");
     gets(destination);

      if (file_copy(source,destination)==0)

          printf("Successful copying.");
       else
          fprintf(stderr,"\nError copying file.");
          printf("%d",file_copy(source,destination));
      return;
 }//end main

      /* write data to new  file */
int file_copy(char *oldname,char *newname)
{
     FILE *fpold,*fpnew;
     int c;
        /*open source file*/
      if ((fpold = fopen(oldname,"rb"))==NULL)
             return -1;

         /*open destination file*/
      if ((fpnew = fopen(newname,"wb"))==NULL)

             return -1;

          /*copy file*/
         while (!feof(fpold))
               {
                    c=fgetc(fpold);
                    fputc(c,fpnew);
                    fputc(c,stdout);
             }

         fclose(fpold);
         fclose(fpnew);
        return 0;

Quote:
}//end function



Sat, 24 Aug 2002 03:00:00 GMT  
 output to screen

Quote:

> I use this code to copy files to files and to screen. When I try to write
> any formatted text out of a word document to screen the results are just a
> series of a's, I presume my text editor can't handle the formatting.

You mean MS-Word? Those are not plain text files. Open them binary, then
decode. The precise encoding is off-topic here, but...
<OT> You may find <http://www.wotsit.org> useful. </OT>

Richard



Sat, 24 Aug 2002 03:00:00 GMT  
 output to screen

Quote:
> out of a word document

You don't mean Microsoft Word by any chance?

Quote:
> I would like to know what the a's are, and also is there any way of
opening
> the documents from C, like opening applications and documents from DOS.

No.

Also, do not use gets(). It is evil. Do it this way:

char buffer[128];

fgets(buffer,sizeof(buffer),stdin);

Yours is a classic use of gets(). Your buffers are too small, and you then
use gets() to maximize the chance of a crash when someone types in more than
40 characters.

Without going over your code in detail, there are a lot of errors. Go
through your own code, and ask yourself what each line does. Notice you are
copying the file twice, and you aren't returning the promised int from main.

--

Paul Lutus
www.arachnoid.com


Quote:

> I use this code to copy files to files and to screen. When I try to write
> any formatted text out of a word document to screen the results are just a
> series of a's, I presume my text editor can't handle the formatting.

> I would like to know what the a's are, and also is there any way of
opening
> the documents from C, like opening applications and documents from DOS.
> Thankyou, Ian.

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

> int file_copy(char *oldname,char *newname);

> int main()
> {

>      char ch,source[40],destination[40];

>      printf("Enter a source filename: ");
>      gets(source);
>      printf("Enter destination filename: ");
>      gets(destination);

>       if (file_copy(source,destination)==0)

>           printf("Successful copying.");
>        else
>           fprintf(stderr,"\nError copying file.");
>           printf("%d",file_copy(source,destination));
>       return;
>  }//end main

>       /* write data to new  file */
> int file_copy(char *oldname,char *newname)
> {
>      FILE *fpold,*fpnew;
>      int c;
>         /*open source file*/
>       if ((fpold = fopen(oldname,"rb"))==NULL)
>              return -1;

>          /*open destination file*/
>       if ((fpnew = fopen(newname,"wb"))==NULL)

>              return -1;

>           /*copy file*/
>          while (!feof(fpold))
>                {
>                     c=fgetc(fpold);
>                     fputc(c,fpnew);
>                     fputc(c,stdout);
>              }

>          fclose(fpold);
>          fclose(fpnew);
>         return 0;
> }//end function



Sat, 24 Aug 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. cannot see output on screen. pls advise

2. stop output to screen

3. Suppressing output to screen

4. Outputting to screen in SDI

5. Problem outputting text to screen, HELP!

6. formatting output from a file on screen

7. Controlling screen output in ANSI C

8. how to control screen output on hpux by c

9. interrupt screen output

10. Child process and output screen buffer

11. How do I suppress output to the screen?

12. Very basic question (output screen to IDE)

 

 
Powered by phpBB® Forum Software