C++ :: How To Do Substring To Get Last 4 Characters
May 8, 2013let says i have char *yytext = "p103_stb" 0r "p0_stb" or "p100_stb"
How to do substr to get the "_stb" in C?
let says i have char *yytext = "p103_stb" 0r "p0_stb" or "p100_stb"
How to do substr to get the "_stb" in C?
I am new to C++ programming, writing a program for the below question:
given a string, how to find the longest substring with all unique characters.
I have a C-based string. trying to remove some sub-string, I got at:
char str[]="alireza tavakkoli";
char* pos = strstr( str, "reza");
for(int j=pos-&str[0];j<pos-&str[0]+strlen("reza");++j)
str[j] = 7;
But I don't like the last line.isn't there a better solution?
How I can search a sub string in a file? Length of sub string is Variable and the number of search is indefinite.
View 15 Replies View RelatedI am stuck in some logic and want to write a program to do following tasks : I have three string variables to be compared to each other,a string having sub string & hierarchy string!!
1.) name1=john name2=tom_john_tom name3=alextom_john
thus we need to search john from name2 and name3 and if name1 exists in both name2 and name3 then ok else check for step2
2.) name1=a.b.c.d ,name2=a.b.c.d and name3=a.b.c.d
we need to compare each string seperated by a dot in all three variables and we need to match each string seperated by a delimeter "."
if name1.a==name2.a==name3.a and name1.b==name2.b==name3.b ,name1.c==name2.c==name3.c and name1.d==name2.d==name3.d then its a match
else its a mismatch
Also,the catch is we can have name1 ,name2 and name3 in format name1=*.*.*.* and name2=*.*.*.* and name3=*.*.*.*
where * defines it can be any value to be matched
name1=government.india.public.property
name2=rural.roads.maximum.x
name3=government.india.public.sales
name4=rural.roads.minumum.x
If operator wants to match only the second field , then the logic should be like:
If the Value is to be matched = (*.#.*.*)
then "matched"
Else
its a mismacth
# => for this field of name2 and name3 shall be same
* => for this field name2 and name3 shall be ignored for comparison
to obtain option1 we can have find function and substr however pls suggest how to approach for second option !!!!
Suppose I have read a line from an ASCII file with fgets(). Now I want to parse the line, which looks something like this: Code: # John Q. Public et al. 2014, to be submitted The name, "John Q. Public" is what I want. However, the name can be anything, consisting of 1 or more tokens separated by spaces. it could be "John" Or "John Public", or "Thurston Howell the 3rd", or etc... Bascially, I need to get the entire substring between the first hash mark, and the "et al" in the line. I tried this: Code: sscanf(line,"# %s et al.",name); But I can only get the first token (which, in this case, is "John").
View 2 Replies View RelatedHere are the requirements for a project I am working on.
Write a function that will write only unique ip addresses to a file (just the ip address, not the entire line).
Write a function that will search for an ip address and display all page requests for that ip address.
The ip is pulled from a "weblog.txt" file which has been put into a vector and sorted. I am having trouble with the loop to pull only unique ip addresses from the vector.
Code:
#include<iostream>
#include<vector>
#include<fstream>
#include<string>
#include<algorithm>
void nonmember();
void sortnonmember(std::vector<std::string>& webvector);
[Code] .....
i couldnt solve the algorithm exactly. The program asks the user for a string. "Bugun h@v@ cok g'uzel" for example. then the program asks for another string. If that string doesnt exists in the main string program should say there isnt any substring. If it exist then the program should print the remaining part of main string. For example:
Write the first string: Tod@y weather is be'@utiful
write the substring : ug
>>ugun h@v@ cok guzel
write the substring :wldnqwbdbj
>>there isnt any substring
Here where i came so far
#include <stdio.h>
int main()
{
char mainstr[50],substr[50];
[Code]....
I would like to compare two strings, one of which is an independently stored string - the other being a string within a vector. However, i do not know how to do this, as
string thisString = "yes";
vector<string> stringHere;
stringHere.push_back("no");
if (thisString == stringHere[0]) {
cout << "It worked." << endll;
}
does not appear to work.
I'm trying to search a specified file for all instances of substring "abbaa."
The professor is making us use a 6x3 array in order to understand finite state machines.
Well the code I wrote runs perfectly, but the case for '/n' doesn't catch. It just flows through without it.
Significant portion of code:
Code:
if(fin) {
fin >> inChar;
while(fin) {
switch(inChar) {
case 'a':
currentState = state[currentState][a];
[Code] .....
How to substring first 8 digits from number?
I have text file with around 10k lines. Each line contains number with length 12-14 digits. I want to take only first 8 digits from each number and writ it in new file.
so my question is i want to print characters,no string just an array of characters,i do this but it s not working,maybe i have to put the '' at the end?
Code:
int main() {
int i;
char ch[5];
for(i = 0; i < 5; i++) {
scanf("%c",&ch[i]);
[Code]...
Im supposed to find the common characters between two string characters, assuming that the user wont input duplicate letters like ddog. When I run my code I get an output of a question mark upside down. Here is my code with comments on what each part is supposed to do
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char str1[20], str2[20],remp = '