C/C++ :: Delete From Sentence All Words With Character Count Which Is Equal To Pair Number

Nov 20, 2014

I have an assigment to make program which deletes from sentence all words with character count which is equal to pair number , for example - [ I like C ] and the result of this program should be [I C] because the word like contains 4 characters which is pair and it should be removed.

So I started writing my program and I am stuck at this block of code -

#include <stdio.h>
#include <stdlib.h>
main () {
char text[100], blank[100];
int c=0,d=0,i,j;
gets(text);

[Code] ....

To explain what is happening - I go through all string and search for first ' ' space symbol and check its value. If it is pair then my program prints that it is not pair[because last character before space had not pair number of characters], but the hardest part comes in when i have two not pair words , because space takes one character and now when i check if i%2 == 1 the answer is false [0] for the second word .

View 2 Replies


ADVERTISEMENT

C++ :: Count Numbers Of Words In A Sentence Simply By Counting Spaces

Jan 22, 2014

I wrote a code that counts numbers of words in a sentence, simply by counting spaces... but instead of showing a true number it shows a wrong number.

#include <iostream.h>
#include <conio.h>
int check(char eh[10000]) {
int he=0;
for (int i=0; i<=10000 ;i++) {

[Code] ....

View 8 Replies View Related

C++ :: Count Number Of Words And Lines Then Print All Words

Dec 20, 2013

I have written below program to count number of words and lines and print the all the words.

#include <iostream>
using namespace std;
#include<fstream>
#include<string.h>
int main() {
ofstream outfile;

[Code] .....

Its compiling fine but when executed its displaying I infinite times...

View 3 Replies View Related

C++ :: A Program To Find All Pair Of Numbers Between 0 And N That Equal K

Oct 29, 2013

int main()
{
int a=0, c, d, N, K;
bool stopBool = 0;

[Code]....

This is supposed to find take a number N and K and find all numbers between 0 and N that equal K and cout the number of pairs that fit it but it doesn't work.

View 2 Replies View Related

C/C++ :: Count The Number Of Words In A String?

Apr 28, 2015

#include <fstream>
#include <iostream>
#include <string>

[Code].....

When I try to run my program I get:

1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:UsersDocumentsVisual Studio 2010ProjectsCS 111Lab10Lab10DebugLab10.exe : fatal error LNK1120: 1 unresolved externals

What I'm trying to do is get my program to count the number of words in an inputted data file. I've attached the assignment directions

Attached File(s) : lab10_data_.zip (9.27K)

View 4 Replies View Related

C# :: Count Number Of Words And Change Them

Jan 31, 2014

I want to count number of words from my textfile and then make the first word ToUpper and second word ToLower and do that for the rest of the textfile.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication3 {
internal class Program {
private static void Main(string[] args) {

[Code] ....

View 14 Replies View Related

C++ :: Validity Of New / Delete Pair (or Malloc / Free) After Pointer Casting

Dec 22, 2012

Goal: To allocate some memory as a char*, read in some binary data, re-interpret it as a float* and then free the memory.

My code looks like:

void someFunction(float* &result) {
char * tmp = new char[1000];
//...Fill the char buffer here...
result = (float*)tmp; //Reinterpret binary data as floats

[Code] ....

Is the cast back to char* necessary on the red line (or could I have validly left it as float*)? Would it be different if I had written char * tmp = (char*)malloc(sizeof(char)*1000); on the blue line (and correspondingly used free (char*)floatData on the red line?

View 9 Replies View Related

C/C++ :: Getting Data From File - Count Number Of Words In A Text File

Mar 27, 2014

I have a program I have to do that counts the number of words in a text file. I have tried the code on 2 computers now since my programming teacher told me the code was fine. Here is my code:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream infile;
infile.open("tj.text" , ios::in);

[Code] .....

View 4 Replies View Related

C++ :: Reverse Words In A Sentence

May 21, 2014

I am trying to write a program in which i enter sentences and then gives the reversed output

E.g.: -

INPUT
Enter the number of sentences
3

This is a sentence
Program
You are great

OUTPUT

sentence a is This
Program
great are You

I wrote the following code but its failing when im trying to enter a sentence

#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
void str(char*, int);
void main() {
char *word[25];

[Code] ....

View 7 Replies View Related

C++ :: Getting The Words (strings) Of A Sentence?

Nov 25, 2013

I am trying to write a code that reads all the words in text according to each sentence from a file. this means i have to signify the end and beginning of every individual sentence the text file. actually am trying to create a summarizer in c++.

View 5 Replies View Related

C :: Reverse The Words In Sentence Program

Feb 5, 2013

Im writing a c program that reverses the words in a sentence,

Example:
you can cage a swallow can't you?
you can't swallow a cage can you?

I have it all working, except the fact that I dont know how to get the words themselves to turn around. Heres my code and an example of the output im getting.

Output Im getting:

Enter a sentence: you can cage a swallow can't you?
Reverse of sentence: uoy t'nac wollaws a egac nac uoy?

Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX 200 /*Decent number of chars for a sentence*/
int main()

[Code] ....

View 2 Replies View Related

C++ :: How To Display Words Splitted From A Long Sentence

Apr 8, 2013

How can i display words form a long sentence.

example :(lets assume that if u find two spaces that is word)

INPUT: the Indian school boys are very good compare to other countries.

OUTPUT: the Indian
school boys
are
very
good
compare to
other countries

I am solving these way but it takes only one space to divide a word.

#include <string>
#include <vector>
#include <fstream>
#include <iostream>
int main() {
std::vector <std::string> words;

[code] .....

View 1 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++ :: 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++ :: Delete Words From A String?

Feb 3, 2015

"Type a function that take in a string containing numbers and others characters and print on stdout all the numbers contained into the string, where for number is mean every maximal numerical sequence, of numbers not separed by spaces. Numbers printed on exit must be separated by commas. For example, if i put in the function the string "paje27hg78 2k f562" my function must print:

27, 78, 2, 562 "

So i started my code like so: (I WANT TO NOTICE THAT WE HAVE ONLY USED IOSTREAM AND FSTREAM LIBRARY FOR NOW, SO DON'T USE OTHERS LIBRARY ELSE MY TEACHER WON'T CORRECT MY HOMEWORK!)

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

[Code].....

View 18 Replies View Related

C/C++ :: To Delete Words (The) From Stream

Dec 14, 2014

I need to use getchar and putchar. The task is simple to say but not that easy to implement as it may seem. I end up with:

char c = 0, c_ = 0, c__ = 0;
while ((c = getchar()) != '.') {
if (c == 't') {
c__ = c;
c = getchar();

[Code] ....

If the word "the" is followed with another one, the last isn't eliminated. I enter "thethe" and get "the", what is not right.

View 1 Replies View Related

C++ :: How To Count Unique Words In A Program

Sep 16, 2013

Write a C++ program that reads lines of text from a file using the ifstream getline() method, tokenizes the lines into words ("tokens") using strtok(), and keeps statistics on the data in the file. Your input and output file names will be supplied to your program on the command line, which you will access using argc and argv[].

You need to count the total number of words, the number of unique words, the count of each individual word, and the number of lines. Also, remember and print the longest and shortest words in the file. If there is a tie for longest or shortest word, you may resolve the tie in any consistent manner (e.g., use either the first one or the last one found, but use the same method for both longest and shortest).

You may assume the lines comprise words (contiguous lower-case letters [a-z]) separated by spaces, terminated with a period. You may ignore the possibility of other punctuation marks, including possessives or contractions, like in "Jim's house". Lines before the last one in the file will have a newline (' ') after the period. In your data files, omit the ' ' on the last line. You may assume that the lines will be no longer than 100 characters, the individual words will be no longer than 15 letters and there will be no more than 100 unique words in the file.

Read the lines from the input file, and echo-print them to the output file. After reaching end-of-file on the input file (or reading a line of length zero, which you should treat as the end of the input data), print the words with their occurrence counts, one word/count pair per line, and the collected statistics to the output file. You will also need to create other test files of your own. Also, your program must work correctly with an EMPTY input file – which has NO statistics.

Test file looks like this (exactly 4 lines, with NO NEWLINE on the last line):

the quick brown fox jumps over the lazy dog.
now is the time for all good men to come to the aid of their party.
all i want for christmas is my two front teeth.
the quick brown fox jumps over a lazy dog.

Copy and paste this into a small file for one of your tests.

Hints: Use a 2-dimensional array of char, 100 rows by 16 columns (why not 15?), to hold the unique words, and a 1-dimensional array of ints with 100 elements to hold the associated counts. For each word, scan through the occupied lines in the array for a match (use strcmp()), and if you find a match, increment the associated count, otherwise (you got past the last word), add the word to the table and set its count to 1.

The separate longest word and the shortest word need to be saved off in their own C-strings. (Why can't you just keep a pointer to them in the tokenized data?)

Remember – put NO NEWLINE at the end of the last line, or your test for end-of-file might not work correctly. (This may cause the program to read a zero-length line before seeing end-of-file.)

Here is my solution:

#include<iostream>
#include<iomanip>
#include<fstream>
using std::cout;
using std::ifstream;
using std::ofstream;
using std::endl;
using std::cin;
using std::getline;
void totalwordCount(ifstream&, ofstream&);

[Code] .....

Question: In the uniquewordCount() function, I am having trouble counting the total number of unique words and counting the number of occurrences of each word. In the shortestWord() and longestWord() function, I am having trouble printing the longest and shortest word in the file. In the countLines() function, I think I got that function correct, but it is not printing the total number of lines. Is there anything that I need to fix in those functions?

View 2 Replies View Related

C++ :: Limit Number Of Flottant To Get Equal Numbers?

Feb 26, 2014

I calculate two numbers "R1",R2"

when i make
cout<<R1;
cout<<R2

i get
R1=51,9151
R2=51,915

when i make

Code: if (R1>R2) cout<<"i am here" he print the message

but they are equal. how i made limit the number of flottant to get equal numbers?

View 13 Replies View Related

C++ :: Program Which Print Out All Prime Numbers Less Than Or Equal To Given Number

Nov 11, 2013

how to make a programm in native c++ which print out all prime numbers less than or equal to given number????????

View 5 Replies View Related

C Sharp :: Count And Delete In File

Oct 16, 2013

So I have this program which read single text file and write in other. Basically read every line then write to another file "this number is n times here + numbers".

How to modify this to store only 1 time the number in second file. What I mean is not like now:

Now output is:

Count of matching numbers in this group: 7
Numbers:
01070400
01070400
01070400
01070400
01070400
01070400
01070400

Is better to be:
Count of matching numbers in this group: 7
Number:
01070400  

Code that I use is:
            string path = "text.txt";  
            var result = (File.ReadLines(path)).OrderBy(x => x).GroupBy(x => x);  
            using (var writer = new StreamWriter("test1.txt")) {
                foreach (var item in result) {
                    string outGrp = String.Format("Count of matching numbers in this group: {0}", item.Count());
             
[Code] ...

View 1 Replies View Related

C :: How To Count And Display Palindrome Words In A Randomized Letters

Oct 11, 2013

how to count and display the palindromes in this randomized letters:

this is my program but it only prints randomized letters and can't count the palindromes words and display it:

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

[Code].....

View 2 Replies View Related

C++ :: How To Delete First Character In Array

May 1, 2014

How do i delete the first character in a character array?

I want output to be

void DeleteFirst (char S[ ])
{
for( int i = 1; i < MAX_LENGTH; i++)
cout << S[i];
}

i am just writing the wrest of the Array without deleting the first. how do i delete the first?

View 7 Replies View Related

C++ :: How To Count Character Occurrence In Array

Jan 17, 2015

i have a problem i cant find a way to count how many times a character occur in a character array the out put should be

a=2
b=1

but my output is

a=2
b=1
a=0

i cant find away to get rid of the other a letter i dont know what to do

#include <iostream>
using namespace std;
int main() {
char array[3] = {'a','b','a'};
char frequency[26] ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

[Code]...

View 2 Replies View Related

C/C++ :: Binary Tree - Count How Often Character (e) Appears In It

Feb 5, 2015

I have a binary Tree and I have to count how often the character 'e' appears in it. Then I have to print it Inorder.

My code:

#include<stdio.h>
#include<stdlib.h>
struct node {
struct node *left;
struct node *right;
char chr;

[Code] ....

But I always get the Error Message "expected ';' ',' '.' or ')' befor numeric constant in this line:

struct node *mkNode(char chr, struct node *1, struct node *r)

View 1 Replies View Related

C++ :: Counting Number Of Vowels In A Sentence?

Nov 29, 2014

I want to count all the vowels in a string (a, e, i , o, u) and display it as a text-based histogram for example:

[INPUT] The black cat sat up on the orange mat!

[OUTPUT]
A: *****
E: ***
I:
O: **
U: *

The asterisks are supposed to correspond to the number of vowels that are counted (using increments and the function setfill()).

#include <iostream>
#include <string>
#include <iomanip>

[Code]....

This is my output during compilation:

[OUTPUT]
The black cat sat up on the orange mat! 0 0 0 0 0
A:
E:
I:
O:
U:

View 1 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







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