C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 25th, 2012, 05:14 AM
lazyman lazyman is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 lazyman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 29 sec
Reputation Power: 0
External data file

This is my program that will ask the user for a list of apps and will store that info and later display it back to them. However it needs to prompt them what is the NAME of the file they are working with first. I basically have an outline of the program but I'm stuck on the part where it prompts them for the file. Every time it askes them for the name of the file and you enter something it closes out the program. Any help would be nice



// Purpose of the program...
// is to manage an array of apps
// providing a way to read and display
// using structures and functions

#include <iostream>
#include <fstream>
using namespace std;
#include <cstring>
#include <cctype>

//Create constants used as array sizes
const int SIZE_TITLE = 131;
const int SIZE_DESC = 300;
const int SIZE_PAGE = 6;


//This creates a grouping for an individual app
struct app
{
char name[SIZE_TITLE];
char description[SIZE_DESC];
char page[SIZE_PAGE];
int length;
};

void displayall(app &); //display all members
void getfilename(char filename[]); //function for getting the external data file
void readall(app &); //reads the input
bool save_app(char filename[], app[], int num);
bool load_app(char filename[], app[], int & num);
void choice(char & x);


int main ()
{
app user[15]; //collection of apps for the user
char filename[35]; //holds the file name
int num_apps=0; //number of apps in the array
char rerun;



getfilename(filename);
if(!load_app(filename, user, num_apps));
cout<<"we are starting from stratch!";


int i = num_apps;
readall(user[i]);







return 0;
}



//Ask the user what file they want to work with
void getfilename(char array[])
{
cout<<"Please enter the name of a file limited to 31 characters: ";
cin>>array;
strcat(array,".txt");

}

//read in all the users apps
void readall(app & user_list)
{
cout<<"Please enter the title: ";
cin.get(user_list.name,131,'\n');
}

//write all of the movies OUT to a file
bool save_app(char filename[], app apps[], int num)
{
bool success = true;
ofstream write;
write.open(filename);

if (!write)
{
cout <<"Can't save, try agian \n\n";
success = false;
}
else
{
for(int i=0; i < num; ++i)
{
write <<apps[i].name <<"|" <<endl;
}
write.close();
write.clear();
}
return success;
}

//load all movies FROM an external file
bool load_app(char filename[], app apps[], int & num)
{
ifstream read;
read.open(filename);

if(!read)
return false;

read.get(apps[num].name,131,'|');
read.ignore(100,'|');
read.close();
return true;
}



//later be used for a loop
void choice(char & x)
{
cout<<"Would you like to add more data?(N or Y) ";
cin>>x;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > External data file


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap