I have started to learn C++ so everything that I am doing is greek to me but I understanding a bunch reading about it. I have this code here (hopefully this will download for you):
http://us.f13.yahoofs.com/bc/43eb0a64me1...
What I trying to accomplish is for function A to load the txt file and function b to display the file. To quit the program I got that down fine. No problems there. What I kinda confused is what command to use to make that happen. |i tried the in File("test.txt" to load but I probably doing it wrong. Thanks for any help on this!
How to load and display data in C++?
First off you are using C and not C++. I changed your code around as your original wasted stack space. Here is the new code
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
#include %26lt;stdlib.h%26gt;
void welcome(void);
void menu(void);
void functionA(FILE **fp);
void functionB(FILE **fp);
int main()
{
welcome();
menu();
return 0;
}
void welcome()
{
printf("%s","Blah Blah\n");
}
void menu()
{
char ch;
FILE *fp;
do
{
printf("%s","Press L to Load\n");
printf("%s","Press D to Display\n");
printf("%s","Press Q to Quit\n");
ch=getch();
if(ch=='l'||ch=='L')
functionA(%26amp;fp);
else if(ch=='d'||ch=='D')
functionB(%26amp;fp);
}while(!(ch=='q'||ch=='Q'));
printf("%s","Thanks for using my program");
}
void functionA(FILE **fp)
{
char buffer[100];
*fp=fopen("myfile.txt","r");
if(fp==NULL)
{
printf("%s","ERROR");
}
}
void functionB(FILE **fp)
{
char buffer[100];
while(fgets(buffer,100,*fp)!=NULL)
{
printf("%s",buffer);
}
printf("%c",'\n');
fclose(*fp);
}
Reply:Ofstream.
Always refer to the API: http://www.cppreference.com
http://www.cppreference.com/cppio/constr...
edit:
it's a luxury that comes with being a mac user
I'm willing to risk getting a virus to help someone out
Reply:First off I would never open a link to a code that someone wants looked at, it could be a virus so easily and then your screwed.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment