Hyena
May 18th, 1999, 12:03 PM
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
//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];
fPtr = fopen("a:\words.dat","r");
fscanf(fPtr,"%s", word);
printf("%s",word);
fclose(fPtr);
}
//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];
fPtr = fopen("a:\words.dat","r");
fscanf(fPtr,"%s", word);
printf("%s",word);
fclose(fPtr);
}