Hi,
I have here a program which count the occurrence of individual characters in a string. If more than one characters are the same and are next to each other (aka: Mazzuzu), you would get 1M, 1a, 2z, 1u, 1z, 1u. I was able to make it work to some extent, but it does not come out completely correct. I think it is a looping and variable issue, but if anything how can I fix it?
------------------------------------------------------------------------------------------C++ program
int main(int argc, char *argv[])
{
string i;
int y = 0;
string input_line;
char ii;
string last = "rWWWora";
for(int ii = 0; ii < last.size()-1; ii++)
{
if(last.at(ii)==last.at(ii+1))
{
y++;
}
else
y=1;
cout<< y<<last.at(ii)<<endl;
}
}
return 0;
}
----------------------------------------------------------------------current output:
1r
2W
3W
1W
1o
1r
------------------------------------------------------------------------------desired output: as an example, I only need 3W because I have 3 W's, which are next to each other.
1r
3W
1o
1r
1a
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
string i;
int y = 0;
string input_line;
char ii;
string last = "rWWWora";
for(int ii = 0; ii < last.size()-1; ii++)
{
if(last.at(ii)==last.at(ii+1))
{
y++;
}
else{
if(ii==0){
cout<<1<<last.at(ii)<<endl;
}
else{
cout<< y<<last.at(ii)<<endl;
}
y=1;
}
}
cout<< y<<last.at(last.size()-1)<<endl;
return 0;
}

Hi, I have here a program which count the occurrence of individual characters in a string....
/* * This program reads characters from stdin and writes them back to stdout. * Student task: change code so that output is rotated output one position * to the left. Thus, if input is "abcd", output should be "bcda". #include <stdio.h> #define BUFFER_SIZE 81 int main(int argc, char **argv) { char string[BUFFER_SIZE]; while(fgets(string, BUFFER_SIZE, stdin) > 0) { int numChars = 0; while(string[numChars] && string[numChars] != '\n') ++numChars; int i; for(i = 0; i < numChars; ++i) putchar(string[i]); putchar('\n');...
Hi! 1. I need some help with sorting string in a text file. My goal is to 1 shift left strings for string.length time. I was able to do that successfully. However, I am also trying to sort, using insertion sort , the resulting shifts. I store all shifts in a vector (or is it better to use an array?!) , and try to sort them that way, but my output is just the shifted strings but not sorted. Can...
Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...
I have included what I need to do for part b, and what I have so
far.
I
2.2 Part B Write a default version of program to report the behavior of the Linux kernel by inspecting kernel state. The program should print the following values to the user screen or console: CPU type and model Kernel version Amount of time since the system was last booted, in thefomdmm:5s (for example, 3 days 13 hours 46 minutes 32 seconds would...
In C Programming Adding to your program in part A, go through the command line arguments and find the largest and smallest arguments by alphabetical order. Note that you should not need to sort your arguments, but instead compare them and save the smallest and largest strings as you go through. For example, if called with ./reverse one two three: It would display the output for part A: Three two one And then it would display The smallest string was:...
1. Suppose you wrote a program that reads data from cin. You are now required to reimplement it so that you can read data from a file. You are considering the following changes. I. Declare an ifstream variable in_file II. Replace all occurrences of cin with in_file III. Replace all occurrences of > > and get_line with the appropriate operations for ifstream objects What changes do you need to make? I, II, and III II and III I and III...
can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define SIZE 100 using namespace std; //declare struct struct word_block { std::string word; int count; }; int getIndex(word_block arr[], int n, string s); int main(int argc, char **argv) { string filename="input.txt"; //declare array of struct word_block word_block arr[SIZE]; int count = 0; if (argc < 2) { cout << "Usage: " << argv[0] << "...
Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...
C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...
I am trying to write a c++ program that will add two binary numbers that are entered into the command line. I cannot get the program to send anything to stdout. code attached. int main(int argc, char *argv[]) // IN IN { char partialSum[MAX_DIGITS + 1]; //partial sum of the binary numbers char sum[MAX_DIGITS + 1]; //sum of the binary numbers bool noError; //no error flag //Exit if insufficient arguments...