A
aldrin
I'm trying to run this code under windows xp sp2 using codeblocks v1.0
compiler with great difficulty.There is no problem with running this
under KDevelop in linux. Any help would be greatly appreciated.
Enter an interesting string.
Too many cooks spoil the broth
Error opening C:\myfile.txt for writing. Program termnated.
This application has requested the Runtime to terminate it in an
unusual way.
Please contact the application's support team for more information.
Press ENTER to continue.
*********************************************************************************
#include <stdio.h>
#include <stdlib.h>
int main()
{
char mystring[80];
int i = 0;
int lstr = 0;
int mychar = 0;
FILE *pfile = NULL;
char *filename = "C:\\myfile.txt";
printf("\nEnter an interesting string.\n");
gets(mystring);
pfile = fopen(filename, "w");
if(pfile == NULL)
{
printf("Error opening %s for writing. Program termnated.",
filename);
abort();
}
lstr = strlen(mystring);
for(i=lstr -1; i >= 0; i--)
fputc(mystring, pfile);
fclose(pfile);
/*ope file for reading*/
pfile = fopen(filename, "r");
if(pfile == NULL)
{
printf("Error opening %s for reading. Program terminated.",
filename);
abort();
}
/*Read a character from the file and display it*/
while((mychar = fgetc(pfile)) != EOF)
putchar(mychar);
putchar('\n');
fclose(pfile);
remove(filename);
return 0;
}
compiler with great difficulty.There is no problem with running this
under KDevelop in linux. Any help would be greatly appreciated.
Enter an interesting string.
Too many cooks spoil the broth
Error opening C:\myfile.txt for writing. Program termnated.
This application has requested the Runtime to terminate it in an
unusual way.
Please contact the application's support team for more information.
Press ENTER to continue.
*********************************************************************************
#include <stdio.h>
#include <stdlib.h>
int main()
{
char mystring[80];
int i = 0;
int lstr = 0;
int mychar = 0;
FILE *pfile = NULL;
char *filename = "C:\\myfile.txt";
printf("\nEnter an interesting string.\n");
gets(mystring);
pfile = fopen(filename, "w");
if(pfile == NULL)
{
printf("Error opening %s for writing. Program termnated.",
filename);
abort();
}
lstr = strlen(mystring);
for(i=lstr -1; i >= 0; i--)
fputc(mystring, pfile);
fclose(pfile);
/*ope file for reading*/
pfile = fopen(filename, "r");
if(pfile == NULL)
{
printf("Error opening %s for reading. Program terminated.",
filename);
abort();
}
/*Read a character from the file and display it*/
while((mychar = fgetc(pfile)) != EOF)
putchar(mychar);
putchar('\n');
fclose(pfile);
remove(filename);
return 0;
}