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
0
votes
1 answer

Strstr Returning NULL

I am running into problems trying to use strstr with the following code. Can anyone point out to me why strstr on line 108 (documented in printf() statement) is returning NULL? I used a file as my command line argument (containing three words…
Slthiess
  • 1
  • 3
0
votes
3 answers

PHP: How to find the beginning and end of a substring in a string?

This is the content of one mysql table field: Flash LEDs: 0.5W LED lamps: 5mm Low Powers: 0.06W, 0.2W Remarks(1): this is remark1 ---------- Accessories: Light Engine Lifestyle Lights: Ambion, Crane Fun Office Lights: OL-Deluxe Series Street Lights:…
Stefan Schneider
  • 157
  • 3
  • 18
0
votes
3 answers

Using strstr in C MBED, printing result

I'm trying to compare two char arrays and print to the terminal whether or not the string was found. When I run my code, the output printed returns a load of jibber that's not related to what I specified. I think more memory than I've specified is…
Charlie
  • 2,876
  • 19
  • 26
0
votes
2 answers

finding how many times the digit 5 appears within 0 - 4322

This code doesnt seem to work for me. it outputs the number 17 which is obviously wrong.the counter should go up if it encounters numbers like 5, 15, 25, 50 ect. #include #include #include #include int…
Bossrevz
  • 33
  • 1
  • 4
0
votes
1 answer

Error when printing out searches for word in a text file using string

I have my code using Visual Basic: #define _CRT_SECURE_NO_DEPRECATE #include #include #include int main(void) { FILE *inputFile = NULL; char line[9999]; char word[9999]; int count = 1; char…
girlbui
  • 1
  • 1
0
votes
2 answers

strstr always returns null

I am trying to get a substring from a CString using C++. For that I am using strstr function. But it is not working at al CString str = m_sectionDataList->GetNext(pos); char* chToMatch = (char*)(LPCTSTR)str; char *match = "="; …
user4604440
0
votes
0 answers

strstr in C using multidimensional arrays

For background, I'm currently working on an assignment to scan Les Miserables (given to me in a .txt file) for character names (a list of which is given to me in a separate .txt file). When a character is mentioned, write which character and which…
DJOwen
  • 21
  • 1
  • 7
0
votes
1 answer

strstr works only if my substring is at the end of string

I've encountered a couple of problems with the program that i'm writing now. strstr outputs my substring only if it's at the end of my string it also outputs some trash characters after that I've had problems with "const char *haystack" and then…
0
votes
2 answers

can't make strstr() work

I have a homwework assignment that I can't get to work correctly at all in one area, specifically where I'm trying to compare strings. Here is the assignment: You will write a program that prompts the user for student names, ages, gpas, and…
Emily
  • 11
  • 3
0
votes
4 answers

how to extract a string using two forward slashes

I have a string which is always has two forward slashes as /709/nviTemp1 I would like to extract the /709/ from that string and return it in char*, how would I use strstr for that purpose? I also might have many forward slashes in the path like…
andre
  • 175
  • 2
  • 10
0
votes
1 answer

Trouble with cin.getline and strstr

Im trying to write a simple program that will read in a list of names and allow you to search through them. Im having a problem with my cin.getline and my strstr. Im new to c++ and im have a hard time getting my head around c string and its…
Doe
  • 33
  • 1
  • 6
0
votes
1 answer

Phone Number Lsit

Write a simple telephone directory program in C++ that looks up phone numbers in a file containing a list of names and phone numbers. The user should be prompted to enter a first name and last name, and the program then outputs the corresponding…
Doe
  • 33
  • 1
  • 6
0
votes
2 answers

Check if a string is the substring of another string

I was having some problem when trying to check if a string is the substring of another string. Here is the expected output: Enter a source string: abc Enter the target string: abcde findSubstring(): 1 Enter a source string: abcde Enter the target…
QWERTY
  • 2,303
  • 9
  • 44
  • 85
0
votes
1 answer

php strstr/strpost not working

I'm working on a quite simple if-else statement, which containes the strstr or strpos condition. The code is : if(strpos(strtolower($ofcountry),"except")){ .... } Can you tell me what is wrong with this code? Greetings Phil
0
votes
2 answers

Saving multiple occurrences of strstr() from a line in C?

This is my first time posting here so I'm sorry if the formatting is a little wrong. Basically my work has asked me to read through an XML (with invalid tags so using a library may be out of the question - I have no control over the XML files), take…