Hyena
May 20th, 1999, 09:51 AM
i'm just beginning files, and am in need of help. program makeword (below) simply saves an inputted word to a file. readword should read this file and print out the word, but it doesn't work. help. i already posted this once, and added the suggested changes, but it didn't make any difference. help.
//program makeword- makes a word and stores it in a file
#include <stdio.h>
#include <iostream.h>
void main()
{
FILE *fPtr;
fPtr = fopen("a:\\word.dat", "w");
char *word = new char[30];
cout << "Enter a word: ";
scanf("%s",word);
fprintf(fPtr, "%s", word);
fclose(fPtr);
}
//============================================================//
//program readword- reads data from makeword
#include <iostream.h>
#include <stdio.h>
void main()
{
FILE *fPtr;
char *word = new char[30];
if((fPtr = fopen("a:\\words.dat","r")) != NULL)
{
fscanf(fPtr,"%s", word);
printf("%s",word);
fclose(fPtr);
}
else { cout << "could not be opened."; }
}
//program makeword- makes a word and stores it in a file
#include <stdio.h>
#include <iostream.h>
void main()
{
FILE *fPtr;
fPtr = fopen("a:\\word.dat", "w");
char *word = new char[30];
cout << "Enter a word: ";
scanf("%s",word);
fprintf(fPtr, "%s", word);
fclose(fPtr);
}
//============================================================//
//program readword- reads data from makeword
#include <iostream.h>
#include <stdio.h>
void main()
{
FILE *fPtr;
char *word = new char[30];
if((fPtr = fopen("a:\\words.dat","r")) != NULL)
{
fscanf(fPtr,"%s", word);
printf("%s",word);
fclose(fPtr);
}
else { cout << "could not be opened."; }
}