C++ :: How To Terminate While Loop With Newline

Apr 24, 2012

I am new to C++ and wrote some code here that is not working how I want it to:

Code:
int main() {
vector<string> distinct;
string parag;
typedef vector<string>::size_type vec_sz;
vec_sz size = distinct.size();

[Code] ....

Basically, if I run it, it takes a string, stores it in a vector string, and then outputs it to the screen as I hit enter. But then it waits for another string to be entered. How can I stop it waiting for new input after I hit enter? I tried comparing parag with and terminating there, but I am getting compiler error. I am using code::blocks.

View 2 Replies


ADVERTISEMENT

C++ :: Terminate Loop When Two Integers Between 1 To 100 Are Equal

Mar 21, 2013

creating a program using while that terminates the loop when two intergers any two between 1 to 100 are equal with each other

View 2 Replies View Related

C :: How To Terminate A Loop If User Inputs Blank Space In A String Or Press Enter

Jan 28, 2015

Code:

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
int main(void) {
int i;
char *str;
int len = 1;

[Code]...

View 3 Replies View Related

C :: How To Get Newline In A File

Mar 3, 2013

I got a program thats get the newline... I am able to get it vertical but im looking for the line to be horizontal. So lets say my text has "this is an example

= 1st line "
"i'm so crazy about c
= 2st line"

My program only gets this...first letter of 1st line and second line.

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
char *filename = "room.txt";

[code] .....

View 5 Replies View Related

C :: How Each Word Newline Program

Feb 26, 2013

Code:

#include <stdio.h>
int main(void)
{
int c;
int inspace;

[Code]....

I tried this code w/o no "inspace" in it and code still worked but if I made more than one blanks between words it happened vertically double newlines etc.. so I just wanna know how this "inspace" makes newline w/o blank line for each word. Is that a flag ?

View 7 Replies View Related

C/C++ :: Newline When Writing To File

Sep 12, 2014

I've got an issue with my code; whenever I add the " " for a newline, a newline is not actually printed onto the file.

Here's my code:

/*
Description: Lists all the files & other directories in the directory passed through argv.
*/

/*
Importing the required headers.
Dirent.h for the dirent struct.
Stdio.h for printf.
Conio.h for File input/output.
*/

#include <dirent.h>
#include <stdio.h>
#include <conio.h>
int main ( int argc, char *argv[] ) {
// Checking that the user has given the correct number of arguments.

[Code] .....

The solutions I've tried are:

Trying to add the ASCII character for a carriage return (13) and newline (10), but it didn't work.Using fputs() and fprintf() - both mentioned in the code.

View 8 Replies View Related

C :: Get Stdin Contents Without Newline Then Replace

Feb 19, 2015

I'm learning internet sockets right now and to that end I've made a simple client/server chat program centered around select(). I've got it to where multiple messages can be sent and received on either side and the "prompt" will move down 1 line each time accordingly.

My only sticking point is when someone is in the middle of typing a message and a new message is received. The message they are currently typing is going to be deleted, so they'll have to start over again. What I want to do is grab the current contents of the stdin buffer (meaning, there's no ), save it, print the received message and move the prompt downward as usual, and then put that saved message back into the buffer, meaning not only is it back on the screen now, it's erasable too as if nothing ever happened.

I know that this will definitely be some very very non-standard C, and that's fine. To that end, I've read that curses, GNU readline, and termios are possibilities for this. I've tried those, but am having trouble making it work.

This will be a moot point when I put a GUI on it soon (probably wx, but maybe Qt) since it won't even be an issue, but I'm determined to make this work. Both systems (the "client" and the "server") are Linux, one being Ubuntu and one being Debian.

View 2 Replies View Related

C :: How To Terminate A Function

Feb 17, 2013

How can I terminate a function?

View 3 Replies View Related

C++ :: Why System Cannot Terminate Itself

Nov 18, 2014

#include <iostream>
#include <string>
using namespace std;

[Code].....

This is my code, when my pintrials = 0, my system cannot terminate but go through the option menu below.

View 1 Replies View Related

C++ :: Use Value 0 To Terminate Program

Mar 20, 2013

"Allow the user to enter an integer, between 1 to 9 only. You may use the value ‘0’ to terminate the program. Then display the output as follows:

Sample Run 1
Enter an integer (1-9):4
1
121
12321
1234321

Sample Run 2
Enter an integer (1-9): 20
You have entered an invalid entry, please try again.

Enter an integer (1-9): 0

(Try to use remark to explain function and process area)

View 3 Replies View Related

C++ :: Newline Character Not Being Picked Up In A Conditional Statement

Jan 15, 2014

I have the following code:

Code:

while (lineread != "
")
{
getline(ifs,lineread);
}

In essence, it reads an input file, line by line until it hits a line only containing a newline character. So if the input text file is:

27
GC0123456
102905908801170--
2034068010201360
3039077011601400
4043086012901400
504709401400
6051010101400

[code]....

It should exit the while loop after hitting line 6. What happens however is that it goes into a perpetual loop and doesnt exit the while loop upon reading line 6.

What I did was changed the code to:

Code: while (lineread != "*")
{
getline(ifs,lineread);
} and the input file to:
27
GC0123456
102905908801170--
2034068010201360
3039077011601400
4043086012901400

[code]....

and finally it stops after line 6. In this case, merely changing the " " conditional character to a simple asterisk character "*" fixes the problem.

However I wish to keep the input text file as is with the newlines, so how do I make it exit the while loop when detecting a as a line?

View 3 Replies View Related

C++ :: Append More Characters After Newline Character In Txt File

Apr 26, 2014

I'm trying append more characters to a txt file after write title of foreground window and a newline character, but after first character, the next appear after a newline. Here is result => [URL].... and here is my code:

I'm using Dev C++ 4.9.9.2 compiler.

Code:

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
using namespace std;
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);

[Code]....

I have made some changes for this =>

Code:

if (str_window)
strcpy(str_window,str_window);
strcat(str_window,"
");
log(str_window);

[Code]...

Now print only first character in digitation after title of active window. Still printing wrong see => [URL]..... Word "good" as sample.

View 10 Replies View Related

C/C++ :: Use EOF To Terminate Inputting Data?

Mar 18, 2013

how to use EOF to terminate inputting data

View 1 Replies View Related

C++ :: Reading And Storing Newline Character Alongside Data

Jan 6, 2014

I am reading data from a text file into a program. I am well aware of the subtle distinctions in the mode of data input/entry when using the stream extraction operator, the get() function, and the getline() function.

My problem is that all of them do not read and/or store the newline character alongside the data read!

Any function that reads and stores data and the terminating newline character together??

View 1 Replies View Related

C/C++ :: How To Null Terminate Unsigned Short

Jul 23, 2014

I've stored a binary pattern in what is interpreted as an unsigned short.

unsigned short byte_one = 128;

I've done some bitwise manipulation and want to store it back into an array, however, it needs to be null-terminated.

buf[1] = byte_one;

How do I null-terminate this?

View 3 Replies View Related

C :: Convert Scanf Output To Long Double And Discard The Last Newline

Apr 18, 2014

My goal is to read a one line file of a comma separated numbers into a floating point array. The numbers have up to 25 positions after the decimal. I'm having two issues with the following code.

1) atof() seems to be returning zeros every time. Why?

2) The last number includes the new line character. How do I get rid of it?

Note that I adapted the scanf command from here: The power of scanf() - [URL], and don't completely understand it.

Code:
#include <stdio.h>
#include <math.h>
//The following will be calculated in the real program.
#define DIM 1
#define N 8
int main()

[Code]......

In the "real" program, N is calculated and known before reading in the file and the file will always have 2 times N numbers.

View 9 Replies View Related

C++ :: Application Has Requested The Runtime To Terminate It In Unusual Way

Jan 13, 2015

this application has requested the runtime to terminate it in an unusual way. contact the application support team for more information!!!

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>

[code].....

View 6 Replies View Related

Visual C++ :: Terminate A Thread When User Push Stop Button

Nov 16, 2012

I have a thread with a while(1) loop in it. When the user push the stop button I would like that thread to end.

I thought about creating a bool and checking its value periodically in the thread and when I push the stop button I change the value of the bool for that the thread breaks out of the loop and finishes.

View 5 Replies View Related

C/C++ :: Find Max Number Entered By User And Terminate When Negative Number Entered

Jul 15, 2014

I am trying to find the max number entered by the user, and it should terminate when a negative number is entered. For my code, it will just end when the user inputs a lower number than the previous. i.e.- 10 20 15 "The highest number is 20" when it should be "10 20 5 40 15 -1" "The highest number is 40". No arrays or do/while loops either.

#include <iostream>
using namespace std;
int Max(int x);
int main() {
int x;

[Code] ....

View 9 Replies View Related

C :: Loop Does Not Work And Program Quits Without Displaying For Loop Function

Oct 13, 2014

We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.

View 11 Replies View Related

C# :: Use Loop To Load Two Forms Back And Forth Then Stop At Loop 4

Feb 15, 2015

I have tried to submit this topic before but i didn't submit my whole code and it was removed. So here it is. All I am trying to do is load form2 from form1 then back to form1 from form2 for a certain number of times the get out of the loop. I am new to C-Sharp and it seems as though I cant seem to figure out a way to do this.

Here is form1 and form2 code. I have commented out a few things I have tried.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code]....

View 3 Replies View Related

C :: Extra Loop Being Executed In Do-while Loop

Jul 1, 2013

Code:
#include <stdio.h>
#include<ctype.h>
void try5t(){

char choice;
int choiceint;

[Code] .....

Loop is repeated an additional time as shown in the screenshot:

View 9 Replies View Related

C++ :: How Much Milliseconds To Loop Through For Loop

Feb 20, 2014

Given a for loop:

int i;
for(i = 0; i < 1000; i++)
;

How many nanoseconds, or microseconds or milliseconds does it take for each iteration? And why do some use it as a timer mechanism?

View 3 Replies View Related

C/C++ :: How To Change For Loop Into Do While Loop

Apr 19, 2014

I already made a nested for loop into a while loop (below this) and now I'm trying to make the outer for loop into a do while loop, but it's not working.

#include <iostream>
using namespace std;
int main () {
int len;
int j;
int i;

[Code]....

And I can't make this code do the same thing. It stops after one loop, instead of continuing to the end. Why won't the loops continue?

#include <iostream>
using namespace std;
int main(){
int len;
cout << "Enter a number: ";

[Code] ....

View 2 Replies View Related

C/C++ :: Convert A While Loop To A For Loop?

Mar 25, 2012

I need to convert the following while loop:

count = 1;
while (caloriesForItem != 0, count != numberOfItems )
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
totalCalories += caloriesForItem;
count++;
}

This is what I have come up with:

totalCalories += caloriesForItem;
for (count = 1; caloriesForItem != 0; count != numberOfItems)
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
count++;
cout << "Total calories eaten today = " << totalCalories << endl;
}

However the output is not the same?

View 6 Replies View Related

C# :: Loop Within A Loop?

Sep 25, 2014

I for the life of me can't get my logic straight. I have 2 lists, 1 a list of text, and the other a list of int.

Here's my main list: List<string> ListNeedToADD = ListOfSPSExt.Except(ListOfReportExt).ToList();
Here's my second list:IEnumerable<int> result2 = Enumerable.Range(1, Convert.ToInt32(myValue)).Except(hostList);

I need to loop through my main list, ListNeedToADD, and for each item in that list, grab 1 value from the 2nd list and send those 2 items to a method. Something like this:

foreach (string myString in ListNeedToADD)
{
foreach (var item in result2)
{
intSort = item;
insertReportLimits(attribTable, myString, intSort, con);
}
}

The problem with doing it the way I am above is it loops through ALL the items for each myString.

For my method, it needs to look like this: insertReportLimits(attribTable, "34257", 22, con); then it would move on to the next: insertReportLimits(attribTable, "34854", 27, con); etc etc.

View 4 Replies View Related







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