This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcc and file reading HELP!!


        Sorry about the message, but I'm having a problem with my "c"
program reading lines of text from a file with gnu-win32.  The file compiles
fine, but when it executes, 
the lines are displayed, and then stack errors are reported to the screen at
the end, terminating the program.  The program appears to work fine on the
Unix operating system we have at school.  Please help, I'd like to get this
working with windows.

here is the program:

#include <stdio.h>
#define maxFilename 40

int main()
{
int OpenFile(FILE **filePoint, char fileName [maxFilename]);
void CloseFile(FILE **filePoint);
void PrintFileContents(FILE **filePoint);

char userFile[maxFilename];
FILE *sourcefp;


   printf("Enter a file to open: \n");
   scanf("%s",userFile);
   printf("file \"%s\" is being opened...",userFile);
   
   if (OpenFile(&sourcefp, userFile) == 1)
   {
      printf("file \"%s\" opened.\n",userFile); 
      
      PrintFileContents(&sourcefp);

      CloseFile(&sourcefp);
      printf("file \"%s\" closed.\n",userFile);
   }

return 0;
}


/* open file for reading */

int OpenFile(FILE **filePoint, char fileName [maxFilename])
{
   if ((*filePoint = fopen(fileName,"r")) == NULL)
   {
      printf("Can't open %s for reading \n",fileName);
      return 0;
   }
   else
   {
      *filePoint = fopen(fileName,"r");
      return 1;
   }
}


/*close file */

void CloseFile(FILE **filePoint)
{
   fclose(*filePoint);
}


/* Print File contents */

void PrintFileContents(FILE **filePoint)
{
   char info[20];

   while ((fscanf(*filePoint,"%s",info)) != EOF)
   {
      printf("%s\n",info);

   }
}


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]