"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;
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 .
I have a challenge to replace all the words "you" in a sentence that is entered by a user to "u". I have got this working but my code is also changing yourself to urself which it should not be doing.
I got a homework that require to count number of words in a text file and also display the first and last 10 words of the text file to the console. I have finished the counter problem and now I struggle showing the first and last 10 words.
#include <iostream> #include <sstream> #include <string> #include <fstream> using namespace std; int tokenize(string sentence, string tokenizedWords[]);
How do reverse every alternate words in a string that I read into my program:
e.g. The mouse was caught in a clothes peg. reversed (including the full stop) The esoum was thguac in a clothes gep.
I could program it to reverse the whole sentence. But no clue how to reverse certain words such as every even word. Do I need a function and/or loop to solve this?
#include<iostream> // allow input and output #include<string> // allow for larger entries of characters using namespace std; int main() { string sentence, reversed_sentence;
I am trying to read user input for recipe ingredients which must include a ingredient name, and may include a quantity and a unit. Example: Stone ground flour 2 cups or Sugar 1 Tbsp or Milk. The problem I am having is that the string gets cut off after a space when multiple words are used for the ingredient name.
I'm looking to take in an array of less than 50 strings, and I want to find all of the unique words in that array (omitting the words that are repeated) and then outputting the unique words and unique word count. My code compiles, but my unique array is couting all of the words contained in the original array regardless of uniqueness.
#include <iostream> #include <string> #include <stdio.h> #include <string.h> using namespace std; int main() { cout << "Please type in some words." << endl; cout << "Type END and return when you are finished." << endl;
[code].....
This is what I get back.
You typed the following 14 words: red, green, blue, red, red, blue, green, blue, orange, red, reg, apple, banana, banana, END,
You typed the following 0 unique words: red, green, blue, red, red, blue, green, blue, orange, red, reg, apple, banana, banana, END
I'm not worried about the unique count yet, I just want to get the unique array containing the correct strings.
and it wil output each word and maybe then can search for similar words if there would be 2 strings then i would use strstr but i dont know how to do with one string.
Creating a C program that can pick words in a string or array and save it in different location, later combine everything in one string or array. It will be using simple programming C code. For example (arrays, pointer) but not interrupts or other string functions.
In a sentence like this: Size= 70 $--GSV,x,x,x,x,x,x,x,...*hh $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,b,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh $--GLC,xxxx,x.x,a,x.x,a,x.x,a.x,x,a,x.x,a,x.x,a*hh $--GSA,a,a,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x.x,x.x,x.x*hh
The program must capture the $--GGA string then extract from this string:
1) hhmmss.ss 2) IIII.II 3) a (if a = to N or S replace N or S with + or - respectively ) 4) yyyyy.yy 5) b (if b = to E or W replace E or W with + or - respectively )
Save them in an array and display as well. After all the saving, the program should combine them to one string. That the final output.
I'm trying to write a short program that takes the input from a user and trims any leading/trailing white space, and then checks how many words are in the string. Problem is, I'm only allowed to use stdio.h and stdlib.h. How can I accomplish this? Also, how would I check if any of the characters which were entered aren't either a number, letter, or '-'?
I want do delete all occurrences of a char in a given string, but I really don't see my error in the code. Here is how I did it:
Code:
char *input = "example_string"; int len = strlen(input); char *new_line[len]; char bad = 'e'; //the one to delete int i; int j = 0;
[Code]...
I get segmentation or bus errors.. And I also don#t understand the warning I get. new_line is an array of chars, and I am trying to assign to it a certain char.