C/C++ :: Find Length Of First Sentence In Input String

Feb 13, 2015

I have a question about finding the length of first sentence in an input string.

For example, let the input string be: dream in code. community learning

The length of first sentence is 13 (blanks are included). My question is how to create conditions for multiple punctuation signs (!,?)? If while loop goes like:

while((str[i]!='.')||(str[i]!='!')||(str[i]!='?'))

it gives me an error for infinite loop.

Code:
#include<stdio.h>
int main() {
char str[100];int i=0,br=0;
printf("enter a string:
");
gets(str);

[Code] ....

View 1 Replies


ADVERTISEMENT

C++ :: How To Find Length Of String

Jul 6, 2014

int t;
string a;
cin>>t;
getline(cin,a);
int len=a.length();
cout<<a<<" "<<len;

[code].....

why is the length 0?what can I do to get the correct length of the input string?

View 5 Replies View Related

C/C++ :: Find Length Of String

Dec 15, 2014

I am stuck here.

printf(" Enter a line of Morse Code for decrypting");
scanf("%s",phr);
len=strlen(phr);
for(a=0;a<36;a++) {
if(strcmp(phr, morse[a])==0)
printf("%c", alpha[a]);
};printf(" ");

The output :

[output] Enter line to encrypt:
..... -.... --...

converting...
5 [/output]

It should read all code, including null. between coded letter one space, between coded word three spaces.

The output should be:

[output]
56 7 [/output]

View 9 Replies View Related

C :: Word Length Statistics For A Sentence

Oct 25, 2014

Write a program that calculates statistics on word length for a sentence. The sentence isterminated by a ',' For each found length of a word the number of words of that length is printed. Only those lengths that are found in the input are printed. Only letters from a-z or A-Z are allowed to form words. Words are separated by a space. No punctuation characters other than ',' are allowed. If any other input character is recognized or the input is longer than 80 characters the program displays "NOT VALID" (see Hints).

Note, that in the case that no word is present in the input, nothing is printed.

% u6_stats

Enter a sentence: Bolt was expected to use the super bark.

Length 2: 1
Length 3: 3
Length 4: 2
Length 5: 1
Length 8: 1

% u6_stats

Enter a sentence: Something wasn't right.
NOT VALID

Thats what i've already done.

Code:
#include <stdio.h>
#include <conio.h>
void main() {
char s[100];
int numOfWords, lengthOfWord = 0;

[Code] ....

So, the problem is that if i inpute a text like"abc abcd abc abc" the result will be like

"length 3: 3 length 4: 1 length 3: 2".

So when the program already compared 1st (here 3) element with others, this element will not be comparing again, but i have the 3d element with same length, and it that case, the program compare it with remained elements and print 2. How can i rework my code, if i don't wont to compare already compared elements.

Second problem is that i need to get results from lowest length till highest.

View 2 Replies View Related

C++ :: How To Find Position Of First String In Input That Matches Regex

Oct 18, 2014

i want to find the position of the first string in input.txt that matches a regex

// Input.txt
[A-Z]o
Hello everyone, i am John It is rainy today

// Here is my code

string temp; // Store "Hello everyone, i am John
//It is rainy today"
temp.resize(500);
char REGEX[500];
FILE *fi;

[Code]....

View 5 Replies View Related

C++ :: Getting Full Sentence To Input?

Oct 29, 2013

#include <iostream>
#include <string>
#include <istream>

[Code]....

It seems like my program doesnt want to take in a sentence, only the first word i type in

View 1 Replies View Related

C/C++ :: While / For Loop User Input Sentence

Sep 15, 2014

I'm not sure what the program's purpose is?

1) Ask the user to enter a sentence. Until you reach the end of the sentence, test each character to count the number of spaces and letters.

2) For every space counted, print "SPACE", then print one "!" for every letter counted on an indented line underneath the "SPACE".

Your test sentence to use is: "The potash feldspars are important rock-forming minerals in plutonic, volcanic, and metamorphic rocks."

HINT: You do not need any strings. You need one while loop and two for loops. <cctype>

View 4 Replies View Related

C++ :: Find Every Permutation With Length From 1 To N?

Jan 29, 2015

I need to be able to find every possible permutation using all possible values of a char. But I have to make it be able to form permutations from a length of 1 to variable N. For example, if N=3, I need it to be able to come up with

0x00
0x01
.......
0x00 0x00
0x01 0x01
.......
0xff 0xff 0xfe
0xff 0xff 0xff

How could I do this. (I would like to avoid recursion, since N might be as large as 50 or 60 and using recursion would most likely cause a stack overflow)

View 3 Replies View Related

C++ :: Input Sentence And Then Output It In Reverse Order

Jun 3, 2013

I need to do program where i will input sentence and then output it in reverse order. Example: today is Monday ----> Monday is today. So I have this:

#include <iostream>
#include <cstring>
using namespace std;
int main() {
char niz[20],niz2[20];
int lenght,k=0;

[Code] ....

For output I only get one word of sentence,example: Monday is today--->today and nothing else.

View 5 Replies View Related

C :: Find The Length Of Char Array

Sep 25, 2014

I am working on a c-programm. In this program I have to convert the amount of money I read on two variables into the corret format. I got Euros and cents on 2 ints. But now I want to add both of those variables in a String (char array). Also i want to find out the length of the new char array.

View 2 Replies View Related

C++ :: For Loop To Find Vector Length

Jul 21, 2013

Ok my assignment has me doing vector math with some canned code provided for me by the instructor This is the header file to the class I'm working with and the .cpp file as far as I've gotten it.

#pragma once
#include "Scalar.h"
class Vector2D {
public:

Vector2D();
Vector2D( const Vector2D& ) ;// copy constructor
Vector2D( Scalar element[2] ) ; // initialize with an array

[Code] ....

I'm having trouble seeing which data members I'm multiplying together and what the initial state, continuing state, and after loop action I'm supposed to be using in the for loop.

View 1 Replies View Related

C++ :: Find Vertical Paths Of Length

Jul 24, 2014

I'm trying to find vertical paths of length n through a 2D grid of numbers. Paths may connect orthogonally or diagonally. An example grid and an example possible path looks like this:

//Grid
0 1 2 3 4 5 6 7

0 2 4 6 4 1 3 4 5
1 5 3 5 8 6 6 6 6
2 3 4 2 1 1 2 5 3
3 3 2 3 3 1 3 4 5
4 3 6 1 1 5 2 5 4
5 2 5 4 2 4 5 6 2
6 6 6 1 1 5 1 4 5
7 1 5 6 4 2 4 2 3

A example possible path of length n = 3 is running from (3,2) to (3,4) - All 1s ...An example of n = 4 is the run of 3s (1,1) (0,2) (0,3), (0,4)

What is an efficient algorithm for solving this kind of problem? I would like to solve (ideally) millions of grids, giving a list for each grid of all possible paths of length for n = 3-6.

View 11 Replies View Related

Visual C++ :: Ask User To Enter A Sentence And Then A Word To Be Searched For In Sentence

Oct 9, 2013

I am trying to write a program that ask the user to enter a sentence and then a word to be searched for in the sentence. The program must then search for the word in the sentence in a loop and continue to output each place the word is found. For example if the sentence is : I like pickles, pickles, pickles

and you searched for pickles it would return pickles found at 7, pickles found at 16, pickles found at 25.

I am having trouble writing the equation to make the find keep searching after each occurrence of the word being searched. Here is the code I have so far

HTML Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string paragraph;

[Code] ....

View 5 Replies View Related

C++ :: Capitalize First Character Of Each Sentence In String

May 31, 2013

Write a function that accepts a pointer to a C-String as an argument and capitalizes the first character of each sentence in the string. For instance, if the string argument is "hello. my name is Joe. what is your name?" the function should manipulate the string so it contains "Hello. My name is Joe. What is your name?" Demonstrate the function in a program that asks the user to input a string and then passes it to the function. The modified string should be displayed on screen. Optional Exercise: Write an overloaded version of this function that accepts a string class object as its argument.

#include<iostream>
#include<cctype>
#include<cstdlib>
using namespace std;
void capitalize(char sentence[], int const SIZE);

[Code]...

Not even sure if I'm headed in the correct direction, but I'm getting the following errors:

E:CPT-233Sentence Capitalizer.cpp In function `void capitalize(char*, int)':
34 E:CPT-233Sentence Capitalizer.cpp call of overloaded `strstr(char&, const char[2])' is ambiguous
note E:CPT-233<internal>:0 candidates are: char* std::strstr(const char*, const char*) <near match>
note E:CPT-233<internal>:0 char* std::strstr(char*, const char*) <near match>

what I'm doing wrong?

View 2 Replies View Related

C++ :: Outputting First Word Of Each Sentence In String

Dec 20, 2014

I have been trying to get this to work for a while now - with no success.

Basically I am trying to write a function which the returns the first word of each input sentence in a single string - this is part of a larger cryptography program I am working on.

So for example, if this string was passed into the function:

"This is what I mean. Is it right? A poor puppy abandoned. Secret torturing of dogs are happening. Message: be on the watch."

It should return:

//declared in class "steganalyse"
string cyphertext;
string punctuation = ".?!;:'";
book is_first_word

[Code] .....

But this only returns the first word:

This

Any other way to return the first word of each sentence in a string.

View 1 Replies View Related

C :: Program Where User Inputs A String And Prints Out Length Of String

Jan 29, 2014

I would like to understand a function on strings. Below is a code that I took from my teacher where the user inputs a string and prints out the length of the string.

Code:
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int i = 0;

[Code] ....

Now I understand that it returns the count in "int" so my question is:

Let's say i declared

Code: int count = 0;
at the beginning of the code and then made
Code: count = strlen(str);
why wouldn't i have the same result? Is there a way to do it also?

View 7 Replies View Related

C++ :: Censor 4 Letter Words String Within Sentence

May 16, 2014

I have a problem with my code. You are given a sentence and you should censor the 4 letter words within the sentence.

#include<iostream>
#include<string>
using namespace std;
int main () {
int N;
cin>>N;
int k,j,counter=0;

[Code] ....

View 1 Replies View Related

C :: Declared A String Constant And Trying To Print Length Of String

Oct 9, 2014

In this code, i declared a string constant and trying to print the length of string. I know that if i write char a1[7] or char a1[] than it runs and give aggregate output, but in this case it is giving double length of string.

Code:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
}

[code]....

View 5 Replies View Related

C++ :: String Copy - Program To Reverse Word Order In Sentence

Apr 2, 2012

I am trying to write a program that takes a sentence and reverses the word order.

For instance This is a Bird would become Bird a is This

Code :

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main (void) {
char input_buffer[1024];
char middle[1024];

[Code] ....

View 3 Replies View Related

C :: How To Validate The Length Of User Input

Oct 24, 2013

For the following program, I'd like to make sure the user input is between 1 and 40 characters. To do this, how would I complete the if statement below?

Code:
char p_input[41];
printf("Enter a name (1-40 characters):");
fgets(p_input, 41, stdin);

if (p_input ....??

View 6 Replies View Related

C++ :: Fscanf And Verifying Correct Input Length

Jan 24, 2012

I am trying to make a program that will read in input in the following format:

| ...text... || ...more text... || ...still more text...|

i.e. every bit of "text" that gets read in is bracketed on either side by the "|" character.

The buffer that i read them into can be of a maximum length of 101 (100 characters plus a terminating null character); this is how I am currently reading in the input:

char readString [100 + 1];
while ( fscanf(infile, "|%1000[^|]|", readString) ){
/*... manipulate readString ...*/
}

How might I design this program so that, should any of the text appearing between the "|" characters exceed 100 in length, it exits and returns a warning?

View 4 Replies View Related

C++ :: Input Number During Runtime - variable Array Length

Nov 28, 2013

I want to ask for a number as an input during runtime and then create an 2-dimensional array of size as specified by user. i.e. if the user inputs 3, the array should be of size 3X3, and likewise...

View 9 Replies View Related

C++ :: Can't Get Length Of String

Nov 20, 2013

I'm trying some codes about string arrays and taking array length. But i have some problems. I can't get length of string and can't send to a function.

------------------------
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
void GetLength(string);
std::string Words[]={"table","gun","programming"};
int main()
{std::string InputWord;

[Code]...

And how can send Matrix to other function?

View 2 Replies View Related

C++ :: Input Length / Width And Height For 3 Boxes - Sum And Average Volume

Dec 6, 2013

How would I make it so that I can have someone input the length, width and height for all 3 boxes and then have it output the sum and average volume? Here's an example of what I would like:

INPUT - Enter Box 1 (Length, Width, Height): 10.1 11.2 3.3
INPUT – Enter Box 2 (Length, Width, Height): 5.5 6.6 7.7
INPUT – Enter Box 3 (Length, Width, Height): 4.0 5.0 8.0
OUTPUT – The sum of the volume is 812.806
OUTPUT – The average volume is 270.935

Here's my original code:

#include <iostream>
using namespace std;
double box(double length, double width, double height); // use double data
int main() {
double sum;
sum = box(10.1, 11.2, 3.3) + box(5.5, 6.6, 7.7) + box(4.0, 5.0, 8.0);

[Code] .....

View 1 Replies View Related

C++ :: Length Of String Array?

Sep 7, 2013

I can't find any method of retrieving the length of an array except for doing this:

string first[] = {"a","be","see"};
int length = sizeof(first)/sizeof(first[0])

This is a very unconventional way of getting the length of an array.

first->length() would return 1 because it returns the number of letters in the first element of the array (which actually makes no logical sense).

first.size() would return 1 aswell as it's practically the same thing.

Since getting the length of an array is such a fundamental feat, how come I can't find a decent method of doing it?
Is there no buildt in method for this? If there is not, why has it not been implemented in the std?

View 3 Replies View Related

C++ :: How To Set Fixed Length For String

May 28, 2013

The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.

it said 1 to 255 characters

i have to use getline(cin,str);

i tried str[255] but some error happen

View 2 Replies View Related







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