473,701 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need to read multiple inputs.

2 New Member
Okay, so I can get this to read the first line of a txt document. I just can't figure out how to get it to read the next lines. I have to use "user_input " in a function. The wait function just waits until the user hits enter. The text document has 11 lines of code. I know this is a total newb question, but I am baffled. The function gets called at the begining of the file.
Expand|Select|Wrap|Line Numbers
  1. int file_run(void){
  2.     char buffer[255];
  3.     ifstream command_input_file;
  4.     command_input_file.open("p3test.txt", ios::in);
  5.     command_input_file.getline(buffer, 255);
  6.     if(command_input_file == NULL){ return 0;};
  7.     strcpy(user_input,buffer);
  8.     wait();
  9.     return 0;
  10.  
HERE IS A PART OF MY CODE -SMALL PART:

Expand|Select|Wrap|Line Numbers
  1. int parse_command_line(void)
  2. {                if(COMMANDS_FROM_FILE == 1){
  3.                 file_run();}
  4.  
  5.                 if(COMMANDS_FROM_FILE ==0){
  6.                 cout << "Enter the Commmand: \n";
  7.                 cin.getline(user_input,' ');
  8.                 }
  9.                 // deliminates spaces and uses to separate tokens
  10.                 character_string = strtok(user_input," ");
  11.                 //compares the length of the string to allowable amount of characters.
  12.                 if( (strlen(user_input)) >= MAX_CMD_LINE_LENGTH){
  13.                         cout << "Please Use " << MAX_CMD_LINE_LENGTH << " Characters or Less.\n";
  14.                         return 0;}
  15.                 //cout << "Your Tokens Are: \n \n";
  16.                 j = 0;
  17.                 //This continues to process each character in the string until it reaches the end.
  18.                 while(character_string != NULL)
  19.                 { //Analyzises each character in the string, one at a time.
  20.                     //character[j] = character_string;
  21.                     strcpy(cStrings[j],character_string);
  22.                     //error case if there are more than the 10 allowable tokens.
  23.                     if(j > (MAX_TOKENS_ON_A_LINE)-1){
  24.                         cout << "Please Enter " << MAX_TOKENS_ON_A_LINE << " Tokens or Less.\n";
  25.                          return 0;
  26.                     }
  27.                     //cout << character[j] << endl;
  28.                     j = j + 1;
  29.                     character_string = strtok(NULL, " ");
  30.                 }  
  31.  
  32. if
  33.  
Feb 6 '07 #1
2 1667
horace1
1,510 Recognized Expert Top Contributor
you could have two seperate functions, one which opens the file and another which reads lines of text, e.g.
Expand|Select|Wrap|Line Numbers
  1. #include <fstream.h>
  2. #include<iomanip.h>
  3. ifstream command_input_file;
  4. void file_open()
  5. {
  6.     command_input_file.open("p3test.txt", ios::in);
  7.     if(! command_input_file)
  8.       {
  9.           cout << " error opeing file " << endl;
  10.           exit(-1);
  11.          }
  12. }
  13.  
  14. int file_run(void){
  15.     char buffer[255];
  16.     command_input_file.getline(buffer, 255);
  17.     if(command_input_file == NULL){ return 0;};
  18.     strcpy(user_input,buffer);
  19.     wait();
  20.     return 1;  // return 1 for OK 0 for fail
  21. }
  22.  
you keep calling file_run() until it returns 0
Feb 6 '07 #2
childofthehorn
2 New Member
Thank You very much it was very helpful!

Doing this fixed it all:

Expand|Select|Wrap|Line Numbers
  1.     if(COMMANDS_FROM_FILE == 1){
  2.                     if(k == 1){ 
  3.                         file_open();
  4.                         k = k-1;
  5.                     }
  6.  
  7.                 file_run();}
  8.  
  9.     if(COMMANDS_FROM_FILE ==0){
  10.             cout << "Enter the Commmand: \n";
I had been staring at this for a couple hours yet.....
Feb 6 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

66
5002
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
1
5520
by: Avin Patel | last post by:
Hi, I am looking for script to allow multiple files can be uploaded/attached in webform ( mostly cgi/perl or php). But I don't like the multiple input boxes using "<input type="file" size="40" maxlength="40" name="filename">" html tag. As it will limit the no. of files can be uploaded(only as many of this boxes I write in form & doesn't look good in form also). I am looking for multiple file upload in web form using "select" or
6
4296
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. Based on the number of variables passed through a GET string, I want to multiply the total number of selected items for each together to see how many possible combinations the selected items are generating. The following snippet of code...
12
5332
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded the custom employee class and have built it as a separate library (employee.dll). This employee.dll is being referenced by both the web service and the windows application. I face the following problem when I send this class to the webservice.
6
3516
by: RobR | last post by:
We have a customer using our application that has a problem. Within our app, we have a two different forms (one generates an email, the other a fax via a webservice). When they click the submit button, IE6 is generating the event 6 times!!! So they end up sending 6 faxes or 6 emails. We simply cannot reproduce this. We can't find anything wrong in our code that might cause this, I can't find anything in MS Technet about IE bugs that...
4
7265
by: jedimasta | last post by:
Good evening all, I'm a relatively new to javascript, but I've been working with ColdFusion and PHP for years so I'm not necessarily ignorant, just stuck and frustrated. Using ColdFusion I'm using an include to pull in form elements (text fields, checkboxes, etc...) multiple times on a single page. The included page does not have a form tag of it's own, but the root page has uniquely named forms for validation. Imagine it like this:
11
3346
by: waffle.horn | last post by:
Hi, if this makes sense i want to create a function that can be called so that it reads a single line from a file, then after using the information destroys it. Such that when the function is called that line of info does not exist anymore in the file. for example i have created a short example of where i am at, but I dont know how to alter what im doing so that i just read in a single line
17
17064
by: Sam Kong | last post by:
Hello, There are 1 or more select elements with the same name in a form. Let's say that the name of the select is 'select1' and the name of the form is 'form1'. If there's only one select I access it like form1.select1. If there are more than one select, I access them like form1.select1. To check if there are more than one, I thought I can use
4
1322
by: pbd22 | last post by:
Hi. In my script the below code creates a new element on the page with an associated delete button: var row_element = new Element( 'div', { 'class':'container', 'events':{
0
8736
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9225
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8934
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7823
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6569
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4410
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3102
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2398
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2035
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.