C/C++ :: Prevent Endless Output Of Sentences?

Nov 16, 2014

After I have compiled and executed code below, and I have made an input of a string, the while loop takes over the control and outputs an endless flow sentences. How can I make sure when an input of string is made, such a thing does not happen? In Python, one can make a type check by the use of type() command, but such a command does not exist in C, so how can I prevent an endless output in case a string input is made by the user?

(The code below is supposed to check whether the number entered by the user is divisible by 7 or not.)

#include <stdio.h>
int main() {
int a = 0;
printf("Input a number!
");
while (1 < 2){
scanf("%d", &a);
if (a % 7 == 0) {

[Code] ....

View 3 Replies


ADVERTISEMENT

C :: How To Prevent A User From Closing Output Screen During Execution

Sep 17, 2013

I created a C program that extracts some information from computer and displays it on screen. It is completed today and is going to be applied to startup programs of domain machines. It runs at logon and takes somewhat 5-10 seconds to finish execution. The output is shown on console screen & user can either close the window by clicking on 'x' or pressing 'Ctrl+c' during execution. How do i prevent both of these events?

Basically the most time consuming processes are

Code: popen("systeminfo","r");
popen("wmic qfe get installedon","r");

1st command is getting OS name,version and hotfixes installed.
2nd command gives me the date of updates installed.

I then filter out data & print required information only.

View 3 Replies View Related

C++ :: Cab Company Program / Endless Loop?

Jan 14, 2015

I'm trying to get this program to return total taxi cab fair an infinite number of times, however, when I use the while statement after for and try to run the program, it just keeps displaying the first total fair rapidly.

specifications:A cab company needs a program to calculate the cost of a cab ride.

The driver will enter the length of the trip in miles.

The miles entered must be greater than 0.

Create a function to calculate the charge. The function should receive one argument, the length of the trip, and should return the total fare for the ride.

The taxi charges a fixed charge of $2.50, plus an additional charge of $1.85 per mile.

Allow the user to calculate any number of trips.

At the end display the total of all the fares.

here is my code:

#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
double getLength ();
int main () {

[code]....

View 3 Replies View Related

C++ :: Linked List Concatenation - Endless Loop

Apr 22, 2013

Having trouble with concatenating a linked list.. When I call the display function for the concatenated list, it loops endlessly?

#include <iostream>
#include <cstdlib>
using namespace std;
#ifndef Null//Null is being defined to 0 here
#define Null 0
#endif

[Code] ....

View 5 Replies View Related

C++ :: How To Count Sentences In A Paragraph

Oct 2, 2013

a sample program using c language on how to count sentences in a paragraph...

View 3 Replies View Related

C++ :: Adding Sentences With Spaces?

Sep 23, 2013

Is there a way in which i can add sentences with spaces in c++ ... Tell me both ways with string and without it ...

View 2 Replies View Related

C++ :: Finding Words / Phrases And Sentences

Sep 29, 2013

I need counting the number of words in this input (use isspace( ) to find breaks between words), the phrases, and the sentences. Here is my code so far:

#include <iostream>
#include <string>
#include <cctype>
int main() {
std::string result ;
std::string line ;

[Code] ....

View 2 Replies View Related

C++ :: Count Number Of Sentences In A String?

Sep 5, 2014

I am writing a program that counts the number of sentences in a string. I count the number of '.' '?' '!'. However, there are Mr. Mrs. PhD. Dr. .

int number_of_sentences = 0;
for(unsigned int i=0; i <= text.length()-1; i++){
if(text[i] == '.' || text[i] == '?' ||text[i] == '!'){
++number_of_sentences;
}
}
return number_of_sentences;

View 3 Replies View Related

C++ :: Reading Complete Sentences From A File

Mar 3, 2013

I need to extract full sentences from a file and the save them in a set. I tried getline to get a full line and then removed the characters after the period. This method doesn't work too well if the other half of the sentence is on another line. How should i fix this?

View 8 Replies View Related

C# :: How To Remove Redundancy With Little Difference In Sentences

Apr 8, 2015

how can i remove redundant sentences from text in richtextbox i.e. exactly same sentences in all text or Sentences that contains two or less than two different words as shown in example one and two.

For exapmle

sentence one: i am john and i am a student.
sentence two: i am stewert and yes i am a student.

Example two

Sentence one: i am john and i am a student.
Sentence two: i am john and i am a student.

"by removing means sentence two should b remove."

example one has only two differences that is consider as redundant too while example 2 is exact copy. so both should b removed. t

View 14 Replies View Related

C# :: Unable To Remove Sub Ordinate Clause From Sentences

Apr 16, 2015

string replace = targetListBox.Text;
replace = replace.Substring(0, replace.LastIndexOf("لیکن"));
targetTextBox2.Text = replace;

i am trying to remove sub ordinate clause from sentences but it ends till لیکن word with all other sentences having no subordinate clause.

View 12 Replies View Related

C Sharp :: Loop In A Button / Runs Endless When Pressing The Button And Not Only Once

Jun 10, 2014

I have an code that makes form window + button bet bigger when pressed each time, but it runs endless till out of screen,

code:
{
int S1 = 300;
int S2 = 0;

[Code]...

make it so it runs only each time i press the button?

View 2 Replies View Related

Visual C++ :: Reading And Outputting Files - Sentences And Abbreviations

Mar 26, 2013

I have got an assignment. It is about comparing two files one file has sentences and the other abbreviations. so far i have managed to compare the abbreviations which appear in the sentence and erase punctuation linked to abbreviations.

However I am currently stuck on putting the punctuation back in when outputting the file. I am also stuck with replacing matching words in the sentences with the expanded abbreviations. Not sure which code to show. but sentences and abbreviations are below.

ABBREVIATIONS

Aberd Aberdeen
admin administration
approx approximate
Austral Australia
div division
Capt Captain
Comdr Commander
e east
HQ Head Quarters
m metres
mil million
mt Mount
n north
NATO North Atlantic Treaty Organisation
NSW New South Wales
pop population
s south
sq square
w west

Text file

NATO troops were on exercise in Aberd Capt Jones of the first div told Comdr Frank that his troops were near the E flank of the NATO forces. Complaining about the amount of Admin, Capt Jones radioed the NATO HQ asked for navigation relative to the HQ. The Captain then left.

For example the abbreviation "Aberd" in the sentence above needs to be replaced with Aberdeen from the abbreviations file. I need the last part of the abbreviation not "Aberd Aberdeen" need just "Aberdeen". Hope the info is understandable.

View 6 Replies View Related

C++ :: Read Sentences From User And Change Them Based On Their Character Choices

Sep 10, 2013

I'm trying to get the hang of the declaration and use of char. I'm trying to write a program that reads sentences from the user and changes them based on their character choices, I keep getting load of compiler errors.......am I off to a good start or am I way off?

#include<iostream>
#include<string>
#include<cstring>
#include<cctype>
using namespace std;
int main() {
char *quit*;
char sentance [100];

[Code] ....

View 3 Replies View Related

C++ :: How To Prevent Loop Running Over

Feb 18, 2014

i am writing a function that takes a delimited string and splits the strings into it's respective words according to the delimeter.

1) iterate through string and store delimeter position in vector array.

2) iterate through again and use substr to split into words and store again in a vector.

I then have a dictionary file, and am comapring each values in the string with each in the dictionary, problem is that it overruns the loop and obviously gives a subscript out of range error.

Code:
#include <iostream>#include <fstream>
#include <vector>
using namespace std;
//Start with string inputString
//Find delimeters ::pos as ints and stores positions in vector <int> array
//Run though string using 'find' and seperate string by positions of char32s
//Build vector<string> array of individual words in string
//Open dictionary file and loop though testing each words in vector string array against each word in dictionary

[code]....

View 4 Replies View Related

C :: Prevent Duplication When Insert Age

Oct 17, 2014

I created program that insert employes data and then print their data but never accept duplicate age if user entered duplicated age prompt him to enter another age (age must be unique)

Code:
#include<conio.h>
#include<stdio.h>
#define size 3

struct emp
{
int age,overtime,dedcution,netsal;
float salary;

[Code] .....

View 3 Replies View Related

C :: Prevent To Type Zero As The First Digit In Value

Apr 4, 2013

I want to prevent to type zero as the first digit in value in c code

Code:
char next_buffer[ 5 ];
int frame_counter;
int digit_counter;
memset( cmd->next_buffer, 0, sizeof( cmd->next_buffer ) );
cmd->frame_counter = 0;
cmd->digit_counter = 0; Code: if( arg && isdigit( arg[ 0 ] ) {

[Code].....

this write in text box numbers from keypad for example

5 0 2 4 9

After each typed digit, here is a underscore line waiting for the next to type next digit. I want to prevent users to type zero as the first digit in value.

View 4 Replies View Related

C++ :: Null Statement - Prevent Optimization

Dec 7, 2014

Recently I was looking into embedded programing of AVR microcontrollers.

At this site [URL] ....

I have encounter some code that implements delay

asm volatile ("nop");

From what I understand it is assembler code that creates delay - one processor clock long.

For C/C++ language it should be like ; or {} = null statement.

Now my question is how to implement this C/C++ code and prevent my compiler (WinAVR: AVR-GCC) to delete this command during optimization (-Os or -O2). Or is it simply better to use the assembler function.

I know I can use for-loop

volatile uint8_t foo
for(foo=0; foo<2; ++foo){}

but for that I have to create a variable = wasting 1 byte of RAM; correct?

View 11 Replies View Related

C++ :: How To Prevent The Main Thread From Blocking

Feb 14, 2014

I have an issue where I iterate through devices and make driver API calls. Unfortunately, these calls take too much time and they are interrupting my real-time scheduler. I have 12 cores, of which one is 100% and the others are < 1%.

I'd like to multi-thread this thing. So far, I've replaced:

for (DeviceIterator d = devices.begin(); d != devices.end(); ++d) {
d->Write(words, numwords);
}

with

void* ThreadedWrite(void* p) {
WritePackage* wp = (WritePackage*)p;
wp->device->Write(wp->words, wp->numwords);
delete[] wp->words;
delete wp;

[Code]...

My problem is that this didn't improve performance at all. The main thread still takes too long to execute. Is there something I need to do to prevent the main thread from blocking?

View 2 Replies View Related

C# :: Prevent Sending Multiple Emails

Dec 10, 2014

I have some code which triggers an alarm when an ascii number is read in on the com port:

In that code, i have it send an email to let me know i have an alarm. The problem is it keeps sending the email over and over until i cancel the alarm. Inbox gets full real quick!

Im having trouble implementing a way to send the email just once! Ive googled as much as i can find but i cant get any way to work.

//QT TANK TEMP TOO LOW:
if (ALARM_TYPE_Value == "5") {
ALARM_TYPE_tb.BackColor = Color.Red;
ALARM_TYPE_tb.Text = " **ALARM**" + Environment.NewLine + " ";
ALARM_TYPE_tb.Text += "

[Code] ....

View 4 Replies View Related

C/C++ :: Prevent Duplicate Entry When Insert Age

Oct 17, 2014

I created program that insert employes data and then print their data but never accept duplicate age if user entered duplicated age prompt him to enter another age (age must be unique)

Here is my code

#include<conio.h>
#include<stdio.h>
#define size 3
struct emp {
int age,overtime,dedcution,netsal;

[Code] .....

View 1 Replies View Related

Visual C++ :: Prevent Executable From Running?

Aug 30, 2013

I would like to programmatically monitor a directory for new files, and if the file happens to be an executable, I want to prevent it from running. Something like a AV program.

However, I don't know where to start. Simple is best.

View 9 Replies View Related

Visual C++ :: Prevent DLL From Being Loaded / Injected

Dec 12, 2012

If you're writing a .dll you can prevent that dll from getting loaded into some processes by returning false from the dllmain.

I'm looking for a way to do it the other ay around. I have an exe, and I want to prevent a certain hook dll from getting loaded/injected into my exe.

A customer is running some software which loads a hook dll into our exe, and this is subsequently preventing our application from running as intended. Both our software as well as the third party app is required, and there is no way to get the third party dll changed. (no longer supported).

View 2 Replies View Related

C++ :: Prevent The Loop From Reading The Last File Line Twice?

Oct 19, 2013

I know how to do it in C, but in C++?

Here is my code. Let the variables be of type double.

Code:
while(infile) // Will read the last line twice
{
if(!N)//Read first line of file
{
infile >> d;
infile >> N;
infile >> epsilon;
infile >> t;

[Code] .....

View 8 Replies View Related

C++ :: How To Prevent Someone Passing Classes To Function Template

Sep 13, 2013

Let say i have a following scenario:

a function like this.

Code:
template <typename T1>
print (T1 x){
cout << x << "
";
}

How do I prevent user passing a class or a structure or aanoter function to my function print. I mean i know if a wrong thing is passed that i'll get an error eventually but is there a way to explicitly check what has been passed. How is this done usually ?

View 6 Replies View Related

C :: How To Prevent Fgets From Reading The New Line Character

Mar 12, 2013

i am trying to read a string using fgets and storing in an array i want to prevent fgets from storing the new line character on the array using the shortest means possible..

View 2 Replies View Related







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