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
4 answers

combine two if conditions results in one if condition

if condition 1 : if(isset($_POST['searchOrder']) && $_POST['searchOrder']!='') { $userToSearch = "WHERE name='Conformed'"; } If condition 2 : if(strstr($status, "value1") !== false ) { $hide .= 'style="display: none;"'; …
user8444404
0
votes
1 answer

How get string before symbol

I have strings TEST #1 - Description TEST #2 / Description ... I need get string before # but with #1, output: TEST #1 strstr($str, '#', true); These code output: TEST i need TEST #1
Shoxa
  • 19
  • 4
0
votes
3 answers

Copying a desired string from a text file in C

I have read all the text from a desired file and it is now stored in buff. I want to copy just the string content after identifier strings such as 'Title'. Example file below: "Title: I$_D$-V$_{DS}$ Characteristic Curves (Device 1) MDate:…
pproctor
  • 101
  • 1
  • 10
0
votes
2 answers

Incrementing char value (more than one letter)

I am confronted with the following code: int get_config(const char *key, char *value) { FILE *fp = NULL; char s[100]; char *ret1 = NULL; char *ret2 = NULL; fp = fopen(CONFIG_FILE_PATH, "r"); if (fp == NULL) { perror(CONFIG_FILE_PATH); …
user3554329
  • 111
  • 2
  • 11
0
votes
3 answers

strstr() function in C programming

I am learning C from the book Head First C, and I tried one of the examples, and despite having the same code, my code won't run like the example in the book. The code aims to use the strstr() function to find a string within another string, but…
0
votes
0 answers

PHP replace only first occurrence in String for each Array value

I have two arrays: $ORGvarvals (ORGvarvals contains the values which needs to be replaced in String) & $varvals (varvals contains the values which needs to be replaced with ORGvarvals in string) $str (Contains the content). This is my…
0
votes
1 answer

Finding the number of occurence of all the permutations of a SubString in a String in C

Basically this program is made up of two other programs. First Part to find the permutations of a Sub-String and the Second Part to find the number of occurence of all the permutations in a given String. I'm not Getting the required output for most…
rsanath
  • 1,154
  • 2
  • 15
  • 24
0
votes
1 answer

How to increment a variable when strstr finds the specified string

I'm wanting to have my variable houseTot increment by one every time strstr finds a string with "house" in it. I've essentially done this in my code: struct Owner1_def { int totProps; char type[40]; float monthlyPrice; float…
Boo92
  • 69
  • 4
0
votes
1 answer

Using strstr method in C with two arrays?

I'm making a morse code translator through the command line but am having trouble comparing the array holding user input to the array holding the morse code equivalents. const char *morse[SIZE] = { "0 ----- ", "1 .---- ", "2 ..--- ", "3 ...-- ", "4…
thale
  • 23
  • 4
0
votes
1 answer

This is giving me typecasting issue. How to store 001 in arg

char *arg; arg = strstr(buff, 001); This is giving me typecasting problem. How to store 001 in arg?
saurabh
  • 17
  • 3
0
votes
3 answers

How to print only the first sentence in string [C]?

Example: void stringEvaluation(char *name){ if (strstr(name, "Tall") != NULL) --here I would like to print only "John Doe"-- } int main{ char name[160 + 1]; scanf("%[^\n]%*c", name); stringEvaluation(name); return…
0
votes
0 answers

C Read, compare and save txt file content

I need to find when the string "#number of points NUM_PT" is seen in the given text file and then get+save the string that is on the next line in the txt file. However, with this code I ultimately save the last string in the text file which is not…
jjyj
  • 377
  • 4
  • 15
0
votes
3 answers

ANSI C strstr() not working with pointers

I'm trying to use strstr() to find a substring in a string. Using char[] works only, char* is not working, gives segmentation fault. So this one is working: int main() { char str[] = "apple apple peach"; char *p; p = strstr(str,…
Janekx
  • 631
  • 6
  • 21
0
votes
2 answers

Copying one part of a string to another in C

I have problems trying to copy one part of a string into a another. Given these two char pointers: line points at string cointaining: "helmutDownforce:1234:44:yes" username points at: NULL Here's my function that takes these pointers as…
cass
  • 11
0
votes
1 answer

why we dont pass pointer arguments in strstr in main function

char *strstr(char *string2, char string*1) In strstr function the arguments are pointer strings but when we pass arguments from main.. Why do we use only strings but not their address? #include #include main() { char s1 [] =…