C :: Find Highest Frequency Character In A String

May 17, 2014

The code shows all characters frequency, however i want to find which one has highest frequency

For example cprogrammmmming cboard
highest frequency: m

Code:
char string[100], ch;int c =0, count[26]={0};
printf("Enter a string
");
gets(string);

[Code] ....

View 3 Replies


ADVERTISEMENT

C/C++ :: Finding Highest Frequency Character In A String?

May 17, 2014

the code shows all characters frequency, however i want to find which one has highest frequency for example cprogrammmmming cboard highest frequency: m

char string[100], ch;int c =0, count[26]={0};
printf("Enter a string");
gets(string);

[Code].....

View 8 Replies View Related

C :: Write Text And Find Frequency Of 1 Chosen Character In It - Input Error Handling

Dec 20, 2014

I'm new in programming, and trying to write a code in C. The requirement is following - to write a text, and to find frequency of 1 chosen character in it. The main thing is that program should check user input (for example, I want to check if user entered "char" --> then correct, or if entered "int" --> not correct). But the program still doesn't check. So I have:

Code:
#include <stdio.h>
int main(){
char c[1000], ch;
char i, count=0;
printf("Enter a text: ");
gets(c);

[Code] ....

Am I on my right way using if/else?

View 3 Replies View Related

C++ :: Find Frequency (string Into Struct Array)?

Apr 17, 2013

I'm trying to figure out the word frequency of a user inserted string. I've tried doing it via getline of the struct array and via the getline of the string word but neither either the former crashes or the latter just prints out the whole string.

Here is the latter.

#include "stdafx.h"
#include <iostream>
#include <string>
#define MAX_WORDS 200
using namespace std;

[Code] ....

How to handle the array of structs.

View 5 Replies View Related

C/C++ :: Finding Highest Frequency From Array Of Characters

Jan 27, 2015

I have been working on a project that deals with an array of characters and finding there frequencies. I was able to determine the frequencies that where greater than 1, but I need to find the HIGHEST frequency.

Here is my full code:

#include <iostream>
using namespace std;
void input(char unlisted[80], int& n);
void bubblesort(char unlisted[80], char sortedlist[80], int n);

[Code].....

As you can see this will print out all frequencies that are bigger than 1, but I only want the highest frequency. Basically I want to print out all frequencies when count is greater than 1 less than count, but because its in a loop count will always be greater than count-1 so it prints out all frequencies.

View 3 Replies View Related

C++ :: Find The Highest Digit Within C-String

Oct 27, 2014

I can't find the highest digit within c-string. Ithe user was to enter 1234. the highest shall be 4 but can't get that number.

int Hnum(char* str) {
//int size = 0;
int H = 0, remainder, div =0;
int intstr = atoi(str);

[Code] ....

View 2 Replies View Related

C++ :: How To Find Position Of Certain Character In String

Jan 11, 2013

I need to find position of certain character in string, so i made a function but it doesn't do what i thought it would.

Consider this string:

std::string line = "<foo> <foo> <foo> <foo> <foo>"

I need to find position of a third '>' character so i can get:

std::string other = "<foo> <foo> <foo>";

This is my function that fails:

std::size_t find_third(const std::string& line) {
std::size_t pos = 0u;
for(std::size_t i = 0; i < 3u; ++i) {
std::string tmp = line.substr(pos);
pos = tmp.find_first_of('>');
} return pos;
}

View 6 Replies View Related

C/C++ :: Program To Find Index Of Character In A String Gives Incorrect Output

Oct 28, 2014

I've been typed out a C program to let the user define the size of their string , and key in characters for this string , the program would then prompt the user for a character to search for in the string and return it's index value. Eg. Index of c in abc is 2. My code is as shown:

#include<stdio.h>
#define SIZE 20
int search(char x[SIZE+1] , int n , char s);
int main(void){
char x[SIZE+1] , s;
int n , index;

[Code] ....

However , after I key in my characters for the string , the program does not prompt me to input a character to look for, it just prints it out and returns some funny number. But the program works just fine is I move this portion to the top :

printf("Enter alphabet to find: ");
scanf("%c",&s);

View 1 Replies View Related

C++ :: Find Highest Value Of Array

Nov 4, 2013

I am currently trying to make a simple method for an array that would find the highest value. here is currently what i got, but do not know what to change to make it correct.

double FindMax(double stock[], int size){
int size = stock.length();
int max = stock[0];

for(int i = 1; i < size; i++){
if (stock[i] > max)
{max = stock{i};}
}
return max;

View 3 Replies View Related

C++ :: Find The Lowest And Highest Temperatures?

Sep 29, 2013

How can I properly find the lowest and the highest temperatures?

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

[Code]....

View 1 Replies View Related

C++ :: Find Highest Prime Of 600851475143

Jun 6, 2013

I have reduced it for lower numbers but for some reason with higher numbers when i get the program to out put all the primes they are in minuses!!!

I need a way to make this even faster, or maybe theres a better mathematical answer, I know that for numbers in their 1,000,000,000,000 have an average of 1 prime every 26.6 numbers (i think thats right there is 37,607,912,018 primes in the number 1,000,000,000,000) is there anyway i can utilize this??

#include <iostream>
using namespace std;
int main() {
int primeanswer = 1,p = 1;
for (int i=1;i<35; i++)

[Code] .....

View 19 Replies View Related

C++ :: Compare Data Stored To Find The Highest?

Aug 13, 2014

How do I compare multiple datas?

I have climate data for 6 months and is trying to find the highest climate month among all 6 months. How do I do that?

View 2 Replies View Related

C++ :: Find Average / Highest And Lowest Score?

Oct 9, 2014

Create a 1-D Array to hold a set of exam scores:

55 74 93 84 64 72 69 78 87 84 72 33 83 68 62 51 88 90

Write a program to do the following tasks:

1. Display scores in rows of four(4) scores.

2. Calculate average score and display.

3. Find Lowest score and display.

4. Find Highest score and display.

5. Find the deviation of each score, and display the score and its deviation.

6. Find the Standard Deviation and Display

7. How many scores are within One Standard Deviation

So I have the average down, but I am getting stuck at the part of displaying the highest and lowest score. Every time I run the program I get two giant negative numbers for both of them. I put all the scores into a .txt file and I just opened in through the program.

#include "TCHAR.h"
#include <iostream>
#include <fstream>
#include <iomanip>

[Code]....

View 1 Replies View Related

C/C++ :: How To Find Highest And Lowest With 3 Inputs In Different Control Statements

Aug 10, 2014

We will make it in Turbo C, C++ and VB.. but as of now (Turbo C and C++)

This is the problem

Make a program based on the given logic below

a>b && a>c - a highest
b>a && b>c - b highest
c>a && c>b - c highest
and will determined the lowest

we will do this in different program control statements:

1.If-Then-Else
2.Multiple-If
3.Nested-If
4.Do Case
5.Do While
6.Do Until
7.For Next
8.Switch
9.Break
10.Loop

is it possible?

View 1 Replies View Related

C/C++ :: How To Find Top 10 Highest And Lowest Numbers From Text File

Jan 3, 2014

I have a list of numbers with decimal point saved in a text file (grade.txt) like this:

80.2
85.7
57.2
90.0
92.9
74.0
76.5
...
I would like to write a small program to display the top 10 highest and lowest grade points.

View 3 Replies View Related

C/C++ :: Replacing Character In String With Another Character

Sep 13, 2014

So I'm trying to create a function that replaces any instance of a character in a string with another. So first I tried the replace() string member function:

In my implementation file

void NewString::ReplaceChar(const char& target,const char& entry)
{
this->replace(this->begin(),this->end(), target, entry);
};

Main program

#include "NewString.h"
using namespace ...;
int main()

[Code].....

Instead of replacing the the l's with y's it outputted a long string of y's. Also, NewString is derived from the string class (it's for the assignment). the header and whole implementation file, already tested.

I've also tried, instead, to use a for loop in ReplaceChar() but I need to overload the == operator and I don't know how I should exactly:

bool NewString::operator ==(const char& target)const {
if(*this == target)
return true;

[Code]....

I want the == operator to test if the value in the char array is equal to target but I'm not sure how to pass in the position. I'm guessing the this pointer in ReplaceChar() is not the same as the one dereferenced in ==() because target is never replaced by entry in the string.

View 5 Replies View Related

C :: Find Character Position - Output 0

Jul 8, 2014

I try to find charecter position but evey time i run my program it give me 0 position why ? Why in my getChar function give me warning statement with no effect i can not understand this warning where is my mistake.

Code:
void getChar(const char* str){
int lenStr = strlen(str);
int i = 0;
int posCharecter = 0;
printf(" %s has %d charecters length
",str,lenStr);

[Code] .....

View 2 Replies View Related

C# :: How To Get Int Value Of Each Character In A String And Then Add Them All Together

Aug 20, 2012

I'm trying to get the int value of each character in a string and then add them all together so I can do a 1's complement of the total value. I'm trying to do simple checkum kinda of thing for verification of data.

For example: string DPacket = "Hello World!";

I would like to have each character added and do the ones complement. Will it be easier to convert first to int and then add or any other easier way? So my result should be the decimal value addition of each character and then do the ones complement to that.

View 5 Replies View Related

C++ :: String Character Removal

Dec 25, 2013

I know how to remove certain characters from a string by using something like this:

Code: string str ("Hello world!");
erase (0, 6);

That's great if I want to do that manually, but say if someone entered a string, how would I automatically remove every other character they entered?

View 4 Replies View Related

C :: Check Certain Character Is In String Or Not?

Mar 6, 2015

I want to check whether a certain character is in a string or not but my code is not working

Code:
#include<stdio.h>
#include<string.h>
int main()
{

[Code].....

View 7 Replies View Related

C :: Insert Character To A String

Feb 26, 2013

Let's say i have a string "file.txt" and i want to insert "_out" to make it look like "file_out.txt"

I don't know how to do this ....

View 8 Replies View Related

C :: Copy A Character To String

Mar 6, 2015

Copy some characters from char * arg to char * first using a loop with specific conditions.

Code:

char * arg;
// set arg some string...
char first_[25];
char * first;
int length;
length=strlen(arg);
for (n++; arg[n] != '}' || n>=length-1; n++)
strcpy(first,arg[n]); // first += arg[n]; I have strcpy(first,arg[n]); but arg[n] is char and strcpy expects char * ;

how to solve this?

View 2 Replies View Related

C :: Display One Character In A String?

Jun 14, 2013

It's been about two years since I last program c, now I need to do it for a basic project. How would I print out one letter in a string?

For example lets say I have a string called str=[Hello]. I want to display the third letter so just the "l". Here's what I have so far:

Code:

#include<stdio.h>
int main() {
char str[50] = "Hello";
printf("The third letter is : %s
",str[3]);
return 0;
}

View 2 Replies View Related

C++ :: Searching For Character In String

Jun 19, 2013

I'm trying to find a < character in a document, get it's position. Then find > and get it's position. Then i want to delete all things between that but runtime is terminating my process so i don't know what to do.

The code:

#include <iostream>
#include <conio.h>
#include <stdio.h>

[Code].....

View 6 Replies View Related

C++ :: Character Displaying From A String?

Jan 27, 2013

I want to input a string, say: abcdaa so, the program should output:

a
b
c
d

In other words, the program will display each character for only ONCE!!!! And display their frequency. Here is my idea: user will input a string and such string will be copied into another string variable called "checker".There will be a loop and each character will be printed, BUT, first, the program will check if the character to be printed is not equals to all elements of the checker string.

I already have the function to count the frequency of each character

GOAL: to make a program that will accept a string and use the HUFFMAN CODING to compress it.

for(x=0; x<string_in.size(); x++) {
cout<<" "<<string_in[x]<<endl;
for(y=0; y<string_in.size(); y++) {
if(checker[y]==string_in[x])
break;
else
checker[x]=string_in[x];
}
}

View 13 Replies View Related

C# :: How To Replace Character In String

Feb 12, 2015

I have an open file dialog that opend the xml file and store the path to the textbox, it returns the path correctly but when i need to store that xml file into the database it tells me that there is an error next to '' because when i try to debug it it gives me "C:\Student Results\FC2015.xml" this results then it breaks. here is my code:

This code returns xml path to textbox

OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "XML Files (*.xml)|*.xml";
ofd.FilterIndex = 0;

[Code]....

View 2 Replies View Related







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