Questions tagged [strstr]

A function that searches a string in another string.

A function that searches a string in another string.

Examples

php
$email  = 'name@example.com';
$domain = strstr($email, '@');
echo $domain; // prints @example.com

(Example taken from php.net)

Resources

363 questions
-1
votes
3 answers

recursive strstr function in c

I wrote my recursive strstr but the problem is that if I have this code: char *str = "Yesterday all my troubles seemed so far away"; char *subStr[6] = { "Yes", "all", "my", "see", "far", "day" }; char *res; int i; printf("%s\n", str); res = str; for…
Tania Galan
  • 3
  • 3
  • 6
-1
votes
2 answers

Count and compute: from files; I;m kinda lost on how to get going (Noobie here)

Im going an assignment on trying to count the number of certain keywords in a source code. I for the life of me just don't know how to do it. For example, my code is suppose to do this number of total lines number and percentage of blank…
jaye31987
  • 13
  • 5
-1
votes
1 answer

Remove substring in c

How to write function that removes sub from string a? For example if string is "Hi I am a noob very big noob" and sub is "noob". It would become "Hi I am a very big " I think I must use strstr and strcat but how?
-1
votes
1 answer

Can I use while(strstr(name[a],sname)!=NULL)

I'm writing a phonebook application and one of the functions is for searching the phonebook by name. The program should print out the names the same way as the user entered them (later I will include the numbers and other info). The phonebook has…
-1
votes
5 answers

Getting the part of a string after the occurrence of last backslash

How to get all letters without the last part of string, for example: $string = 'namespace\name\driver\some\model'; The expected output is: namespace\name\driver\some\
Michał Ziembiński
  • 1,124
  • 2
  • 10
  • 31
-1
votes
4 answers

I am trying to compile a simple string but it does not work... why?

My compiler is Code::Blocks. I am trying to eliminate vocals from a character sequence. #include #include using namespace std; char sir[256]; int i=0; int main (){ cout<<"sir=";cin.getline(sir,256); for…
-1
votes
1 answer

strcasestr not working properly

I have two struct arrays and a nested for loop. There are words that are identical in the two arrays, but strcasestr is not detecting them. I used strcasestr to also find substrings within words that are identical. Here's a snippet of my…
IC2D
  • 471
  • 4
  • 11
  • 22
-1
votes
1 answer

C String Checking

I'm new to C specifically and I'm trying to check some strings. The following is my code, commented to indicate the issues that I don't understand why they are occuring: if (strstr(recBuff, "GET / HTTP/1.0\r\n\r\n") != NULL) //Send HTTP/1.0 200 …
Edge
  • 2,456
  • 6
  • 32
  • 57
-1
votes
2 answers

printf("%s",pch) VS. while(printf("%c"pch[i]))?

I have a string: "This is a simple string" My objective is to find (with strstr) "simple" and replace it with "sample". CODE: #include #include #include int main (int argc, char *argv[]){ char *str; char…
mf_
  • 605
  • 8
  • 17
-2
votes
1 answer

How to read an ascii stl file to print it to a file?

How to read an ASCII STL file cubea.stl to print it to a file output.dat? I wrote a part of the program, but this main.cpp doesn't work. I'm probably missing some programs in main.cpp. main.cpp #include #include #include…
-2
votes
1 answer

How to use strstr() function?

I have two files blacklist.txt and email.txt. The blacklist.txt contains some domain names. The email.txt also contains a few domain names. I have to compare both files and find the domain names of blacklist.txt into email.txt using the strstr()…
sanober
  • 21
  • 5
-2
votes
2 answers

strstr function misundersandings

There is a problem with strstr function. I have tried to compile password program, but it falls. Any help would be highly appreciated #include #include using namespace std; int main(){ char s[5], password[]="kuku"; …
-2
votes
2 answers

Using self made strstr() function to check an embedded string in some other string and then replacing it by some other string (input by user)

I am writing a program that uses an array of pointers to strings str[].It receives two strings str1 and str2 and check if str1 is embedded in any of the strings in str[].If str1 is found, then replace it with str2. for example: if str1 contains…
LocalHost
  • 910
  • 3
  • 8
  • 24
-2
votes
2 answers

How to use fscanf without knowing the length of strings in every line

To my understanding, there is a way to parse input such that: A million $ exit $$$ 16 The Cheit and its Punishment $$$ 8 War and Remembrance $$$ 12 Winds of War $$$ 12 How to Play Football $$$ 12 Ultrashort Pulses $$$ 8 Nonlinear Optics $$$ 8…
-2
votes
1 answer

how to get value stored within double inverted commas

char string[200]="ret=\"y\" err=\"000\""; char stringg[50]; char *arg; arg = strstr (string, "ret"); memcpy(stringg,arg+5,1); printf(stringg); I want to copy value of "ret",above program gives the output but when value of ret…
saurabh
  • 17
  • 3