C++ :: Outputting Contents Of Stack On Input Line?

Sep 3, 2013

outputting the contents of my stack on the input line.

View 7 Replies


ADVERTISEMENT

C++ :: How To Stop Outputting Data Based On A User Input

Sep 27, 2013

how to stop outputting data based on a user input. The text file is as follows:

1. a
2. b
3. c

and the code I'm using is as follows:

int main (){
string line;
int search;
cout << "Enter a number from 1-3" << endl;
cin >> search;
search++;
ifstream myfile ("example.txt");

[Code]...

What I want to do is to just output number 1 (the whole line) if the user enters number 1. However, I get an error on the second condition w/c is the "&& line!= search"

View 1 Replies View Related

C++ :: Reading Contents Of A File From Command Line

Feb 7, 2014

i would like to read the content of a text file data.txt (line by line ) directly from the command line using this command: a.exe < data.txt.

What could be the c++ code to read/get the content of these lines (without using ifstream). The treatment of the lines is not a problem for me but i really don't know how to access the content of the file from the c++ code

View 2 Replies View Related

C :: Read Txt File And Print Contents Numbering Each New Line Of Text?

Apr 25, 2013

I have written the following code but i am stuck. Write a program that will prompt the user for a file name and open that file for reading. Print out all the information in the file, numbering each new line of text.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
int main()
{
char line[81], filename[21], c;
int i = 1;
FILE *inFile;

[code]....

View 3 Replies View Related

C++ :: Store User Input Then Display Array Contents?

Jan 10, 2015

I'm coding a hangman game. I'm trying to store user entries so i can output them to show the user what they have already entered. Problem is that it's not display anything at all.

I'm trying to store multiple characters of course, and then display all characters stored.

char guess[27]={0};
cin >> guess[26];
int hit=0;
for(int i=0; i<len; i++) {
if( guess[26] == hidden_word[i] ) {
hit++;
select_word[i] = guess[26];
if(strcmp(hidden_word,select_word) == 0) {

[code]....

EDIT: I also get the error - Stack around the variable 'guess' was corrupted. At the end of the game.

View 6 Replies View Related

C++ :: Display All The Contents Of A File Excluding One Based On User Input

Mar 10, 2014

i want to display all the contents of a file excluding one based on user input say i have 4 records in the file numbered 1 to 4....the user chooses 2 to exclude it outputs records 1,3,4,4 when it should be records 1,3,4 what am i doing wrong here is the code.its basically displaying the last record in the file twice

void excludeRecord()
{
ifstream read;
read.open("Data.txt");
int recordC =0;
string fnameC = " ";
string lnameC = " ";

[Code]...

View 2 Replies View Related

C++ :: Zero In List Contents And Multiset Contents

Apr 24, 2015

HTML Code:

So I insert values from a vector into a list and into a multiset, and I noticed zero is added to their contents! I had to do a whole lot of debugging to find out where the error was, how can i stop this thing? Code which generates such error...

infact i checked the content of vector ups to be sure that there was no zero in it, but after loading into list combi_t * head, it seems like there was a zero added and this is giving me errors when i call function master_roller...

Code:
void ins(combi_t * &testa, int &numero, int &num, int &no)
{ // if (ricerca(testa, numero) == 0)
//{
combi_t *temp = new combi_t;

temp->val0 = numero;
temp->val1 = num;
temp->val2 = no;
temp->nextPtr = 0;

[Code] ....

View 2 Replies View Related

C :: How To Read A 2 Line Input

Mar 13, 2013

I want to be able to read 2 line input, then safe them in separate arrays.

line1 input=array1
line2=array2

View 7 Replies View Related

C/C++ :: How To Get Input From User At Same Line

Dec 8, 2014

I am trying to get my input from user in the same line with certain width between but my output is not in the same line. my third variable which is fruit[i] is shown one line below . How I can fix this ?

#include <iostream>
using namespace std;
int main () {
int staff[3] , fruit[3];

[Code] ....

View 5 Replies View Related

C++ :: How To Input Two Variables From Same Line

May 27, 2014

How to input two variables in the same line? Like when i type 12 and press enter, 1 must be assigned to a, and 2 must be assigned to b. I want it to be entered on the same line, and press enter only once. How do i do that?

View 5 Replies View Related

C :: Have One Line Of Input Trigger Actions?

Nov 26, 2013

I want the phrase "BUY TICKET" to trigger something, i'm thinking an if statement, and then assign the number after the phrase to another variable. There will also be other commands entered from the input file such as "BUY RAFFLE' "TOTAL REVENUE" on the following lines. Sounds like I need to compare a string(?) to a constant phrase, and if they match have it run the specific code?

Code:

//scan in from file
fscanf(ifp, "%c", &input);
if (input == 'BUY TICKET'){
//Run this
}

How to do it using the tools in C.

View 4 Replies View Related

C :: Why Not The First Line At The Standard Input Read

Mar 21, 2013

Here's my code, it's for a poker hand evaluator

input:
'ad 2d 3d 4d 5d...
...4s 5s 6s 7s 8s'

I think it should go through all the 10 crads and disply the name of each card, but it seems to only do it for the second hand

Code:
include <stdio.h>
#include <ctype.h>
int main( void ) {
char inputtedhand[64];
int z=0, counter=0;
int index;
int i=0,m=0,n=0;

[Code].....

View 3 Replies View Related

C++ :: Input Three Names And Print Each One At Different Line

Dec 10, 2014

We need a program that takes three names ( first middle last ) and print it each one at a different line...

View 5 Replies View Related

C++ :: Input Txt File Using Cmd Line Arguments

Apr 9, 2012

I am trying to use the command line to put a txt file in this code. I do Project->set project arguments in code blocks and nothing happens. How does one set up the arguments and where do i do it in codeblocks?

Code:

int main(int argc, char *argv[]) {
char name[20];
struct artist *ptr;
char lineBuffer[LINEBUFFERSIZE];
artistNodePtr startPtr = NULL; /* initially the artist list is empty */
FILE *musicFile;
char *artistTemp, *discTemp, *yearTemp, *trackTemp, *songTemp;

[Code] ....

View 2 Replies View Related

C :: Pointers Array De-allocation And Input In A Line

May 24, 2013

I have three questions concerning the below code I have written, which is expected to do basically as the attached diagram illustrates:

Code:
#include <stdio.h>
#include <stdlib.h>
double getAverageGrade(int studentGrades[] , int size);
int* getStudentInfo(int * numCourses);
int main()

[Code] ...

(1) How may I display the averages to 2 decimal places, namely why doesn't %.2lf work? The program gives 89.00 for 89 and 90, for instance.
(2) How may I read the number of courses and the relevant grades in a row for each student?
(3) How may I free (de-allocate) my array of pointers, namely grades? Does it suffice to use free(grades)?

View 12 Replies View Related

C :: Use Fgets And Sscanf To Read A Line Of Input

May 21, 2014

I'm new to C/C++. I am attemping to use fgets and sscanf to read a line of input, and confirm it is a positive number.My code works great, except for the case of a negative number. When I enter a negative number, my while loop seems to run infinitely, with stdin providng the same input over and over again.

Here's the code snippet:

Code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define TEXT_LEN 64
void foo() {
char* inStr = (char*)malloc(sizeof(char)*TEXT_LEN);
memset(inStr, 0, TEXT_LEN);
}

[code]....

View 9 Replies View Related

C++ :: Using Getline Multiple Times On One Line Of Input

Sep 15, 2014

I've been stuck on this for hours, and have scoured the internet for any insight on this particular issue with no luck.

I'll simplify the problem here. I have a lines in an input file:

John Smith 1234 Main St New York
Carol Thomas 5678 5th Ave Columbus
...
and I am reading into character arrays using code like this:

infile.getline(name,20);
infile.getline(street,15);
infile.getline(city,10);

but when I print the output using something like this:

outfile << "Owner Name: " << name << endl;
outfile << "Address: " << street << city << endl;

(let's pretend I included spaces between the address components, which I omitted to save space)

I get an output file of:

Owner Name: John Smith
Address:

The output stops after the name variable, which I believe is stored correctly. I don't think anything is storing in the address pieces, this is the problem.

I think it's because I'm not using getline() properly in this case. Can you string together multiple getline()s like that?

If this was my design, I'd read in strings instead, but that is not possible in this case.

View 6 Replies View Related

C++ :: Input Elements Of Two Dimensional Array In Same Line

Nov 4, 2013

I want to input the elements of a two dimensional array in the same line . So while giving input . when i press enter . it should remain on the same line ? HOW to do that ?

View 1 Replies View Related

C :: Prompt User For Input And Display Character In Every Line

Mar 17, 2013

I am having problems printing "->" on the beginning of each line, im trying to do it as a loop and ending it when the user types "q". also i would like to know how to ignore text from the user when the input begings with a specific character. heres what ive done so far, and not currrently working as expected.

Code:
#include <stdio.h>
int main (void) {
char prompt;
printf("~~~ FRACTION CALCULATOR ~~~

[Code] ....

View 1 Replies View Related

C :: Make Array Stop Reading From Input When It Hits A New Line?

Nov 25, 2013

I want the numbers to be put into the array until it hits a new line. Maximum number of numbers is 1000. What can I replace that while loop with to stop it from reading further into the input file?

Code:

while (input != '
'){
for(i=0; i<1000; i++)
fscanf(ifp, "%lf", &auctions_prices[i]);

View 2 Replies View Related

C++ :: Record User Input But Combine It With Command Line Arguments?

Aug 15, 2013

I want to be able to write a program where I can record user input but combine it with command line arguments. For example I do a simple getline(); and the user types test how to combine it so it could be like test /q and it gives a different output depending on what additional input was added. Can this be done with lots of different inputs?

View 8 Replies View Related

C++ :: Input And Output Files - Names Should Be Read From Command Line

Aug 3, 2014

I am having an issue with the statement "Both the input and output files' names should be read from the command line." I don't understand what this means or what I need to do.

View 4 Replies View Related

C/C++ :: Program Takes Integer Input And Displays Each Digit On New Line From Right To Left

Jan 23, 2015

I'm trying to create a program that takes an integer input and displays each digit on a new line from right to left.

An example of this would be:

Enter an integer: 657
Digit (1): 7
Digit (2): 5
Digit (3): 6

So far I have this:

#include <stdio.h>
#include <math.h>
int main() {
int i, input, output;
printf("Enter an integer: ");
scanf("%d", &input);
if(input == 0)
printf("Digit (1): 0");

[Code] ....

It works perfectly fine, but I just learned that I am not allowed to use the #include <math.h> so I have to take out floor, log, and pow.

I'm pretty sure I have to do some sort of while or for loop to get the results, but how to do it.

View 6 Replies View Related

Visual C++ :: Search Function - Ask User To Input Name And Brings Out Line From TXT File Containing Information

Dec 8, 2013

How to get this thing to work. All i need to do is ask user to input a name and then it brings out the line from the .txt file containing the information.

For example in my case I'm doing a member search function I'm required to ask user to input the name of the customer and then print out all the details (which consumes 1 text line in the .txt file)

Here is the code, This is the write to text file method (100% working)

Code:
cout << "Customer Name: ";
cin >> name;
// ...
ofstream myfile("customer.txt", ios::app);

[Code] .....

View 3 Replies View Related

C :: How Can A Multi-line String Be Read Line By Line

Mar 7, 2014

How can a mulitline string be read line by line

ex: str = "PERIOD="week"
DAY="day"
TIME="time"";

View 2 Replies View Related

C++ :: String Outputting Twice?

Nov 3, 2014

When I run the program, the prompt I am giving the user before I collect their data, shows up twice in row. Here's the part of the code I'm referring to:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
// method prototypes
void characterInstructions();
void phraseInstructions(); //

[Code] ....

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved